Voyager Custom HTTP Controllers

Posted In Voyager
  • jim-adamek 2 years ago
    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 <code>config/voyager.php</code>  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 <code>config/voyager.php</code> 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!!
    
    
    

    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 2 years ago
    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](http://i.imgur.com/aN8QhsC.png)
    
    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](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.

    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 2 years ago
    Thanks Tony!
    
    Now that I see your answer, I think it is in my best interest to use the <code>VoyagerBreadController.php</code> 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](https://www.youtube.com/watch?v=ML_lS-rmTfk&index=5&list=PL_UnIDIwT95PEQFNdgXZGo5SYU5V_TQvc) and sure enough, we created the model in  <code>App\Product.php</code> and called it <code>App\Product</code> 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 <code>browse.blade.php</code> and <code>edit-add.blade.php</code> 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!

    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!

  • jorge-aguirre 2 years ago
    @jim-adamek could you give permission to a role in the custom controller? I create one for a table but I just can not give or take away permissions of the bread in that one, do you know how to do it?

    @jim-adamek could you give permission to a role in the custom controller? I create one for a table but I just can not give or take away permissions of the bread in that one, do you know how to do it?

  • vitor-micillo 2 years ago
    Hi Guys,
    I will reopen this topic with a new question.
    Is there a Controller template that I can use as a template to create something custom and use with BREAD?

    Hi Guys, I will reopen this topic with a new question. Is there a Controller template that I can use as a template to create something custom and use with BREAD?

Please login or signup to leave a response.

Login

or Sign Up

Sign Up

or Login
×
Want to create your own SAAS?

I can teach you to create your own Software as a Service. Click here to learn more!

Visit SAAS Adventure!