How to create custom controller in Laravel Voyager

raff picture raff · Feb 12, 2018 · Viewed 17.1k times · Source

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 ?

Answer

FloatingKiwi picture FloatingKiwi · Feb 13, 2018

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