title: Trying to get property of non-object Laravel with php5.6 installation
body: <p>any help is appreciated :</p>
  
  <p>**the database have the tables created and working fine  : **</p>
  
  <p>but the browser returns error (Trying to get property of non-object (View: )</p>
  
  <p><strong>The controller file is  :</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  use App\Models\DocTracking;
  use App\Models\User;
  use Exception;
  use Auth;
  use PDF;
  use QrCode;
  use Carbon;
  use Validator;
  use Illuminate\Support\Facades\input;
  
  
  class DocTrackingController extends Controller
  {
      public function __construct() {
          $this-&gt;middleware('auth', ['only', 'getDashboard']);
      }
    public function index(Request $request,$id=null)
      {
          if(!Auth::check()){
              return "Please Login";
          }
          if($id != null){
              $userid= $id;
          }
          else {
              $user_id= Auth::user()-&gt;id;
              $selluser = User::find($user_id);
          }
  
         $data = DocTracking::all();
          $data = array(
      'name'=&gt; $request-&gt;name,
              'start_date'  =&gt;Carbon::parse( $request-&gt;start_date),
              'end_date' =&gt;Carbon::parse( $request-&gt;end_date),
              'amount' =&gt; $request-&gt;amount,
              'merchant_id'=&gt; $user_id
    );
  /*
    $doc_data  =  DocTracking::all();
          $doc_data = response()-&gt;json($data);
          $doc_data = json_encode($data);
  
         return view('doctracking.doctracking' ,['selluser'=&gt;$selluser, 'doc_data' =&gt; $doc_data]);  // return view('doctracking.doctracking',compact('doctracking') );
  
  
      }
    public function add_doc(Request $request)
      {
          $validation = Validator::make($request-&gt;all(),[
              'name'=&gt; 'required',
              'start_date'=&gt; 'required',
              'end_date'=&gt; 'required',
              'amount'=&gt; 'required',
              'select_file'=&gt; 'required |image |mimes:jpeg,png,jpg,gif,svg |max:2048',
          ]);
  
  
          $this-&gt;validate( $request, [
              'name'=&gt; 'required',
              'start_date'=&gt; 'required',
              'end_date'=&gt; 'required',
              'amount'=&gt; 'required',
              'select_file'=&gt; 'required |image |mimes:jpeg,png,jpg,gif,svg |max:2048',
          ]);
  
           if ( $validation-&gt;passes())
           {
  
              $user_id= Auth::user()-&gt;id;
  
               $image = time().'.'.$request-&gt;file('select_file')-&gt;getClientOrignalExtension();
               $request-&gt;file('select_file')-&gt;move(public_path('images'), $image);
  
              $file=$request-&gt;file('select_file');
              $uploaded_file_path='';
              if($file!=null) {
                  $destinationPath = 'images/docktracking/';
                  $uploaded=$file-&gt;move($destinationPath,$file-&gt;getClientOriginalName());
                  $image= $uploaded-&gt;getPathName();
                  $img_name= $file-&gt;getClientOriginalName();
              }
              $data = array(
                  'name'=&gt; $request-&gt;name,
                  'start_date'  =&gt;Carbon::parse( $request-&gt;start_date),
                  'end_date' =&gt;Carbon::parse( $request-&gt;end_date),
                  'amount' =&gt; $request-&gt;amount,
                  'merchant_id'=&gt; $user_id,
                  'image' =&gt;$img_name
  
              );
  
              $doc_data= DocTracking::create($data);
              return response()-&gt;json($doc_data);
  
      }
  }
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>The model file is :</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class DocTracking extends Model
  {
      protected $table = 'doctracking';
  }
  ?&gt;
  </code></pre>
  
  <blockquote>
    <p><strong>the view file is :</strong></p>
  </blockquote>
  
  <pre><code>@foreach ( (array)$doc_data as $data )
            {{  $data-&gt;id }}
  @endforeach
  </code></pre>
  
  <p>i think that if   {{$data->id}}    get the data then every thing will work fine  </p>