i need to pass a variable $empresa
to my route, but it can't find it.
find the route only as ( / )
Route::get('/', function() {
if (Auth::guest()) {
return redirect('/home');
}
else {
$empresa = Auth::user()->empresa;
return redirect('/' .$empresa);
}
});
I only get this problem in web.php
file
help please
CodePudding user response:
That' likely because you haven't declared a controller for the route /
with parameter.
It's not always a best practice to declare a controller right in route file like this. But let's ignore that and continue.
Route::get('/', function() {
if (Auth::guest()) {
return redirect('/home');
}
else {
$empresa = Auth::user()->empresa;
return redirect('/')->with(['empress' => $empresa]);
}
});
Just make sure that you have declared a controller for /{empress}
route. Something like this:
Route::get('/{empress}', 'YourController@methodName');