Answer the question
In order to leave comments, you need to log in
How to fix Laravel "Trying to get property of non-object" error?
Route that sends data to the database:
Route::get('/admin', function () {
$posts = DB::table('posts')->get();
return view('admin-panel', compact('posts'));
});
@foreach ($posts as $posts)
@if( $posts->post_type == 'category' )
<tr>
<td>{{ $posts->title }}</td>
<td>
<button id="edit_category_{{ $posts->id }}" class="btn_edit danger"><i class="fa fa-trash-alt"></i></button>
<button id="remove_category_{{ $posts->id }}" class="btn_edit warning"><i class="fa fa-pencil-alt"></i></button>
</td>
</tr>
@endif
@endforeach
@foreach ($posts as $posts)
@if( $posts->post_type == 'product' )
<tr>
<td>{{ $posts->title }}</td>
<td>{{ $posts->description }}</td>
<td>{{ $posts->category }}</td>
<td>{{ $posts->code }}</td>
<td>{{ $posts->price }}₽</td>
<td>
<button id="edit_category_{{ $posts->id }}" class="btn_edit danger"><i class="fa fa-trash-alt"></i></button>
<button id="remove_category_{{ $posts->id }}" class="btn_edit warning"><i class="fa fa-pencil-alt"></i></button>
</td>
</tr>
@endif
@endforeach
Answer the question
In order to leave comments, you need to log in
The cycle is written incorrectly
@foreach ($posts as $post)
{{ $post->title }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question