Support the ongoing development of Laravel.io →
Requests Views

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.

Last updated 3 years ago.
0

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);

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.