How to create custom controller in Laravel Voyager

丶灬走出姿态 提交于 2019-12-30 05:06:07

问题


I am very new in Voyager.

I have got all the controllers inside TCG\\Voyager\\Http\\Controllers while installing Voyager but didn't find other controllers those I have created using BREAD.

Besides that I want to create custom controller in my Voyager admin panel inside App\\Http\\Controllers\\Voyager . I also followed the steps of Voyager tutorial in Youtube for making custom controller, but couldn't create.

Anybody help please ?


回答1:


In your config\voyager.php file add your namespace:

'controllers' => [
    'namespace' => 'App\Http\Controllers\Back',
],

Then publish voyageres controllers to your namespace

php artisan voyager:controllers

Within that namespace create a new controller derived from VoyagerBreadController

namespace App\Http\Controllers\Back;

use Illuminate\Http\Request;

class SchoolController extends VoyagerBreadController
{

Then you can specify the controller in the bread editor.

NOTE: I did have to refer to mine as Back\SchoolController instead of just SchoolController as I would have expected.




回答2:


Update: From version 1.1 now you need to extend VoyagerBaseController instead of VoyagerBreadController.




回答3:


Add this to your model.

use Illuminate\Database\Eloquent\Builder;

protected static function boot()
    {
        parent::boot();
        static::addGlobalScope('order', function (Builder $builder) {
            $builder->orderBy('name', 'asc');
        });
}


来源:https://stackoverflow.com/questions/48743770/how-to-create-custom-controller-in-laravel-voyager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!