0

i want to change the actual location of the view file that is rendered when view() is called in laravel. For eg. My view structure is this.

   resources
       view
          frontend
             home
                index

But is want (using this code)

   return view('frontend.index); 

to actually call (emulate below code)

   return view('frontend.home.index);

is there any way to accomplish this? Maybe modify the view() function so that it appends the param before processing the render.

in short
can i change the way view() finds the location of the blade file in laravel?

Another way of explaination

Whenever i call any view from frontend folder like

    return view('frontend.index')

Is there a way to globally change the parameter i.e. ('frontend.index') to ('frontend.home.index');

PS. I am trying this for allowing users to choose multiple theme for the frontend. so i can directly add all integrations to a certain theme and save the theme as "black" inside the frontend folder of view. so the "black" will change according to the theme name . in the above example the name of the theme would be "home".

Update:
What i have done is that now i have made a view service provider and now calls

   View::composer('frontend.*', function($view){

   }); 

under boot method.
So now can i somehow change the view that is to be fetched before the view class actually checks whether the view file exists or not and change the view file that is to be rendered.

user575272
  • 112
  • 9

2 Answers2

0

You can try this

resources
    views
        frontend
            index.blade.php
A.A Noman
  • 5,244
  • 9
  • 24
  • 46
  • no no .. i actually want to run the first code but want it to render using the second code. is there a way to modify how the view() works ? so that maybe i can change the parameter from frontend.index to frontend.home.index . – user575272 Jun 15 '20 at 05:52
0

So i found that instead of changing the actual path i might just change the base_path for the view so my folder structure now being

   resources
      view
         themename
             frontend
                  index

So in order to set a dynamic view path. In to boot method of a service provider

    View::getFinder()
        ->setPaths([
            base_path('resources\views\\'.$theme)]
        );

How to set view file path in laravel?
Having a dynamic View folder path during runtime in laravel 5.3

Seems i just didnt know what to search for.

user575272
  • 112
  • 9