How to create custom controller in Laravel Voyager

前端 未结 3 1598
予麋鹿
予麋鹿 2021-01-01 03:13

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 co

相关标签:
3条回答
  • 2021-01-01 03:58

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

    0 讨论(0)
  • 2021-01-01 04:06

    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');
            });
    }
    
    0 讨论(0)
  • 2021-01-01 04:14

    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.

    0 讨论(0)
提交回复
热议问题