Hi all,
I am trying to implement google amp for my site, in which case if the request contains a query param ?amp=1
then I'll resolve the view to a different directory.
For e.g.
return view('home')
//currently resides in /resources/views
but the same should resolve to /resources/views/amp/
if the query param is present.
Can it be done through a middleware ? I believe the only way to implement this is to extend the view and return a customview from the controller
return customview('home')
//now this resolves to /home.blade.php or /amp/home.blade.php depending on request query param
Any help would be greatly appreciated.
Wrote a method in Controller.php
public function customView($viewPath, $viewArr)
{
$amp = Request::input('amp');
if ($amp) {
return view('amp.' . $viewPath, $viewArr);
} else {
return view($viewPath, $viewArr);
}
}
and from other controllers returned something like this :
return $this->customView('home',$viewArr);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community