Trying to get property of non-object laravel 5.4 -
we have project upgraded laravel v 5.1 v 5.4 , many issues , bugs appear after upgrade anyway have 1
trying property of non-object index.blade.php and code
<tbody> @foreach($routefemails $routefemail) <tr> <td>{{ $routefemail->id }}</td> <td>{{ $routefemail->routef->id }} ({{ $routefemail->routef->vessel_name }})</td> <td>{{ $routefemail->creator->type }}: {{ $routefemail->creator->first_name }} {{ $routefemail->creator->last_name }}</td> <td>{{ $routefemail->status }}</td> <td>{{ $routefemail->created_at->format('y-m-d h:i') }}</td> </tr> @endforeach </tbody> i check model , no value mention null no null
i did
php artisan cache:clear php artisan route:clear php artisan view:clear and function in co controller
public function index() { $routefemails = routefemail::orderby('id', 'desc')->paginate(10); return view('backend.route_f_emails.index', compact('routefemails')); } how can fix ? :(
your problem compact(), return type of compact() array [read here], when passing compact('routefemails') converting object array.
in index.blade.php accessing values of $routefemails object. can try 1 of below solutions.
solution 1
write <td>{{ $routefemail['id'] }}</td> instead of <td>{{ $routefemail->id }}</td>
or
solution 2
write
return view('backend.route_f_emails.index', ['routefemails'=>$routefemails]); instead of
return view('backend.route_f_emails.index', compact('routefemails'));
Comments
Post a Comment