Route:
Route::controller(PublicController::class)->group(function () {
Route::get('/index', 'index')->name('public.index');
});
View:
index.blade.php
wrong_browser.blade.php
In controller, this way is ok:
class PublicController extends Controller
{
public function index(Request $request)
{
if(is_wrong_browser)
return view(public.wrong_browser);
return view('public.index');
}
}
But how can I return view from another function, like this, without making a new route:
class PublicController extends Controller
{
public function index(Request $request)
{
$this->CheckBrowser();
return view('public.index');
}
public function CheckBrowser()
{
if(is_wrong_browser)
return view(public.wrong_browser);
}
}
2
Answers
You can use the method redirect.
You could use middleware which you either define globally, or on specific routes.
It is bad practice to return a view from middleware instead redirect your user to another route.
Alternatively, you could have a base
Controller
that yourControllers
extend which has thecheckBrowser
function defined on it and the extendingControllers
therefore have access to: