I am having a hard time to get over this. Try to display a a single item by ID from database. I set the controller and route, but couldn't make it. Getting error or getting no data by the changes that I make on my show.blade
This is my whole controller:
public function welcome()
{
$estates = array();//here
$data['estates'] = $estates;
return view('welcome', $data);
}
public function search(Request $request)
{
$q = $request->q;
$estates = \DB::table('allestates')
->where("building_name", "LIKE", "%" . $q . "%")
->orWhere("address", "LIKE", "%" . $q . "%")
->orWhere("company_name", "LIKE", "%" . $q . "%")
->orWhere("region", "LIKE", "%" . $q . "%")
->orderBy('price')->paginate(10);
return view("search", compact('estates', 'q'));
}
public function show(allestates $allestates)
{
$estates = allestates::where('id', $allestates->id)->first();
return view('pages.show', ['estates' => $estates]);
}
}
Show function must be the problem, but what is the problem I couldn't figure it out.
This is the route:
Route::get("/", "PagesController@welcome");
Route::any("/search", "PagesController@search")->name('search.route');
Route::get('pages/{id}', 'PagesController@show');
And this is the show.blade.
<tbody>
<tr class="even">
<td></td>
</tr>
</tbody>
The first error is this:
Trying to get property of non-object (View: /var/www/html/laravel/resources/views/pages/show.blade.php)
After got this error I changed the show.blade to this, No error shows with this but also there is no data. So what do you think?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire