R
R
Roman2019-02-05 18:55:14
Laravel
Roman, 2019-02-05 18:55:14

In Laravel 5.7, how can I conveniently place all template files in a separate views subfolder?

Hello.
The bottom line is this:

I want to make the design of the project in the form of a separate "theme" (like in WordPress), so as not to overwrite the templates already created using, for example, make:auth, etc. templates, but simply make new ones in a separate folder.

But writing a new path for each view (in the controller or router) is a pain. I would like to somehow do it more centrally, and to make it easy to change and so that such a change does not cause new problems later, in general, according to the mind. And I don't know how to do it.
I was advised in a related topic:
make your implementation of ViewComposer on top of the existing one so that it automatically includes the theme you need in the path

and
You don't need to google anything, because it's unlikely that you'll find it. But you can try: "laravel ViewComposer override" or similar. Plain OOP + ioc laravel.
but I'm new to Laravel, and it sounds like "avada kedavra" to me.
Please poke your finger on what and where to write so that Laravel takes views for not in , but, say, in or something like that. Thanks a lot.
Auth::routes(['verify' => true]);
resources/views/auth
resources/views/mytheme/auth

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gomer1726, 2019-02-05
@procode

The most primitive method is to simply substitute the
Controller prefix

private $viewPath = 'site';

//просто подставляешь
return view($this->viewPath . 'index');

And so each controller has its own path, but of course look for this is not the best option
You go to config/view.php
'paths' => [
        resource_path('views') . 'сюда свой путь',
    ],

and be sure after that
php artisan config:cache
php artisan cache:clear
and all

W
Wentixon, 2019-02-05
@Wentixon

Firstly, it must be said that this is rarely required on Laravel projects, it is still not cms, but if there is a serious redesign, then in any case, you will most likely not return to the old one. If you use git, you can always revert to the old design. But again, the design is changing and most likely some of the functionality will also change and this functionality will not be compatible with the old theme.
Secondly .. if you still need to do this (the only option when you really need to see something like this: one topic during the day, another at night. Something like that), just make the appropriate key in the config, in the base controller, from which all the rest are inherited make a view method, where you already define the full path to the theme view. Or you make a trait in which, again, you create such a method. That's actually all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question