How to create custom controller in Laravel Voyager

2019-02-11 03:09发布

I am very much 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 follow the steps of Voyager tutorial in Youtube for making custom controller, but can't create.

Any body help please ?

3条回答
▲ chillily
2楼-- · 2019-02-11 03:29

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.

Setting controller on backend

查看更多
趁早两清
3楼-- · 2019-02-11 03:35

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

查看更多
ら.Afraid
4楼-- · 2019-02-11 03:46

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');
        });
}
查看更多
登录 后发表回答