Voyager Custom HTTP Controllers

jim-adamek

Mar 18th, 2017 02:41 AM

Hello developers,

I am converting an existing site into Laravel Voyager admin. I have some reports with tables, and large tables that need accordion or tab type entry to make them managable.

I know I will need to use custom HTTP controllers. I have read the documentation at Voyager Docs on the subject. There are two things I would like to understand better before I make that attempt:

I am new to a lot of this so bear with me please.

One: in the config/voyager.php do we leave the existing namespace for all the TCG controllers? I will want to use the standard TCG controllers when I can.

'controllers' => [
    'namespace' => 'TCG\\Voyager\\Http\\Controllers',
],

For this situation will I end up with two namespaces in the config/voyager.php as follows:

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

Let me know how I can accomplish that.

Second: Normally routes in the Voyager admin are defined in the menu builder bread system. When we want to use a custom layout do we need to override routes as explained in docs and how do we incorporate that in the menu builder?

If you want to flesh this out in a video, I would love to see it... explanations will do as well.

Tony thanks for your work. I get it when you show stuff in the video and it really helps. Also thanks to Mark for maintaining such a great admin program... really awesome and versatile!!

tnylea

Mar 18th, 2017 04:40 PM

Hey Jim :)

Thanks for the thorough explanation on what you are trying to accomplish and thanks for the acknowledgement on the project. I'm glad to see so many people are finding the Voyager admin useful for their projects.

So, you basically want to override a controller for a specific data type, right? You should be able to do this in the latest version of Voyager. If you go to the database and edit the BREAD of the datatype, you should see these bread options:

Voyager Bread Options

You should be able to add a custom controller in the settings and that will be used instead of the default BreadController :)

I'm actually not too familiar with how the controller overriding works in the config, I think that Mark might be able to shed a little light on how that works. But if you want to specify a specific controller for a Datatype you can do that in the bread options.

You can always use the default BreadController to copy and paste into your custom controller as a starting point and make modifications as needed to that controller: https://github.com/the-control-group/voyager/blob/master/src/Http/Controllers/VoyagerBreadController.php

Let me know if that helps you out :) And thanks again for asking a question here in the forum.

Talk to you soon.

jim-adamek

Mar 21st, 2017 03:41 AM

Thanks Tony!

Now that I see your answer, I think it is in my best interest to use the VoyagerBreadController.php as much as possible. I just looked up the validation process in Voyager documentation and they make it easy to put validation into the Optional Details fields of the Bread menu for the given table. So I should be able to handle all the permissions needed and BREAD processes within Voyager.

I looked at the Product table you created in your YouTube series on Voyager in Lesson 5 and sure enough, we created the model in App\Product.php and called it App\Product in the BREAD Model Name field. So now I think I get it.

I just need to create some custom views for my more complex tables/layouts and place them in the browse.blade.php and edit-add.blade.php as explained in Voyager Docs in the section called Overriding Views. They suggest starting with the existing templates and updating them as needed for our needs. That sounds like a good plan!