laravel 设置模板风格

暂无标签

新建
/app/Providers/ThemeServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Contracts\View\Factory as View;
use Illuminate\Support\ServiceProvider;

class ThemeServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot(View $view)
    {
        $theme = 'default';
        $view->addNameSpace('theme', [
            base_path()."/resources/views/$theme",
            base_path().'/resources/views/default',
        ]);
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {

        //
    }
}

再打开
/config/app.php
'providers' => []里增加

App\Providers\ThemeServiceProvider::class,//theme

模板指定

return view('theme::index', ['lists'=>$lists]);

引入的方式

@include('theme::layouts/index_left')