0
I have slugs stored in the database of different tables, I intend to use the url always like this www.exemplo.com/slug
.
For this I created a single route for that which became so:
Route::get('{slug}', 'SlugAppController@view');
This route redirects to a controller
where I’m trying to validate whether when a person presses a category view
categories, if a user shows the view
user profile.
What happens when I click on a category shows the category well without problems, but when accessing a user shows the following error.
Errorexception in Slugappcontroller.php line 24: Trying to get Property of non-object in Slugappcontroller.php line 24
Line 24 corresponds to if ($result_categorias->slug == $slug)
this error happens when I am trying to access a user www.exemplo.com/cesar-sousa
this Slug exists in the database.
From what I understand of the error it returns as null no if ($result_categorias->slug == $slug)
and the categories, I think how I’m trying to access a user he shouldn’t even enter the first if
but I’m not sure I can count on your help in solving this.
Controller
public function view (Request $request){
$slug = $request->slug;
$result_categorias = DB::table('colecoes')->where('activo', '=', '1')->where('slug', '=', $slug)->first();
$result_users = DB::table('users_social')->where('activo', '=', '1')->where('slug', '=', $slug)->first();
if ($result_categorias->slug == $slug) {
return self::estabelecimentos($request, $slug);
} else if ($result_users->slug == $slug) {
return self::perfil($request, $slug);
} else {
return redirect('home');
}
}
Put the complete error
Trying to get property of non-object
, line and file type, the way it is there is no way to be sure.– Guilherme Nascimento
I already put the link I put at the end has all the error that presents
– César Sousa
This isn’t the whole mistake, it’s the Exception’s way, the mistake is just this
ErrorException in SlugAppController.php line 24:
Trying to get property of non-object
in SlugAppController.php line 24
, I’ll edit the question– Guilherme Nascimento
Which line is 24?
– Guilherme Nascimento
What’s on line 24?
– Kayo Bruno
put in question
– César Sousa