Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom controller in Laravel Voyager

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 ?

like image 413
raff Avatar asked Feb 12 '18 10:02

raff


People also ask

How do I customize my Voyager?

With the installation of Voyager you will find a new configuration file located at config/voyager. php . In this file you can find various options to change the configuration of your Voyager installation. If you cache your configuration files please make sure to run php artisan config:clear after you changed something.

Is Laravel Voyager free?

Voyager is a free and open-source admin panel for the Laravel application. It will take care of your administrative tasks and database tables. Here are some features of Voyager: Voyager has BREAD(Browse, Read, Edit, Add and Delete) functionality.


2 Answers

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

like image 127
FloatingKiwi Avatar answered Oct 18 '22 22:10

FloatingKiwi


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

like image 24
Gourav Pathela Avatar answered Oct 18 '22 23:10

Gourav Pathela