title: User Submitted Posts Store function using Laravel
body: <p>So in addition to my prior topic (thank you guys for helping) <a href="https://stackoverflow.com/questions/43455324/user-submitted-posts-using-laravel">routes with compact</a></p>
  
  <p>I am now facing troubles with my store function, I am getting the error : "Trying to get property of non-object.</p>
  
  <p>This is my store function in my Controller</p>
  
  <pre><code>    public function store(Request $request)
  {
      // validate the data
      $this-&gt;validate($request, array(
              'title' =&gt; 'required|max:255',
              'body'  =&gt; 'required'
          ));
      // store in the database
      $userpost = new Usp;
      $userpost-&gt;title = $request-&gt;title;
      $userpost-&gt;body = $request-&gt;body;
      $userpost-&gt;save();
      Session::flash('success', 'The blog post was successfully saved!');
      return redirect()-&gt;route('admin.userposts.show', $userpost-&gt;id);
  }
  </code></pre>
  
  <p>This is the view to create userpost(to make it more clear, p.s. the same form with different route ofcourse, works for my simple posts but not for my user submitted posts)</p>
  
  <pre><code>@extends('index')
  @section('index-stylesheets')
  
      {!! Html::style('css/parsley.css') !!}
  
  @endsection
  @section('content')
              &lt;h1&gt;Create New User Post&lt;/h1&gt;
              &lt;hr&gt;
  
              {!! Form::open(array('route' =&gt; 'admin.userposts.store', 'data-parsley-validate' =&gt; '')) !!}
                  {{ Form::label('title', 'Title:') }}
                  {{ Form::text('title', null, array('class' =&gt; 'form-control', 'required' =&gt; '', 'maxlength' =&gt; '255')) }}
  
                  {{ Form::label('body', "Post Body:") }}
                  {{ Form::textarea('body', null, array('class' =&gt; 'form-control', 'required' =&gt; '')) }}
  
                  {{ Form::submit('Create Post', array('class' =&gt; 'btn btn-success btn-lg btn-block', 'style' =&gt; 'margin-top: 20px;')) }}
              {!! Form::close() !!}
  @endsection
  
  @section('index-scripts')
  
      {!! Html::script('js/parsley.min.js') !!}
  
  @endsection
  </code></pre>
  
  <p>Method of showing the post:</p>
  
  <pre><code>    public function show($id)
  {
      $userpost = Usp::find($id);
      return view('admin.userposts.show', compact('userpost'));
  }
  </code></pre>