themosis / plugin

Themosis framework plugin boilerplate.
54 stars 19 forks source link

Implement backend routing system for admin pages #6

Closed acermez closed 7 years ago

acermez commented 7 years ago

Add a simple routing solution for backend admin pages created by Themosis Framework plugins in order to point admin pages to Controller methods (something like Herbert Plugin Builder)

acermez commented 7 years ago

@jlambe, as per your request, here is how I imagine the creation of backend pages:

Page::add([
    'type'   => 'parent-page', // Could be replace with parent => null
    'as'     => 'MyPluginMainPage', // Would be used to retrieve the Page URL with a helper
    'title'  => 'My Plugin Name',
    'slug'   => 'my-plugin',
    'icon'   => 'dashicons-format-aside',
    'order'  => '20',
    'uses'   => 'MyPluginController@defaultMethod', // Default method if no actions provided

    // Route mapping
    // In a way the URL would end with ?page=my-plugin-slug&action=actionName 
    'actions'    => [
        'index'    => 'MyPluginController@SomeMethod', // URL => ?page=my-plugin&action=index
        'add'   => 'MyPluginController@AnotherMethod',
        'edit'   => function(Request $request) { 
            // Some logic...
            //....
            // Return view or redirection 
            return view("some.view");
        },
    ]

]);
Page::add([
    'type'   => 'child-page', // Could be replaced with parent => parent-page-slug
    'parent' => 'MyPluginMainPage',
    'as'     => 'MyPluginSubPage',
    // Same for the parent-page type from above...
]);

I know it is kind of Herbert Panels declaration, but I think it is easy to use and time saving solution since we can't use Laravel like routes on backend. Please correct me if you think this doesn't make sense :)

jlambe commented 7 years ago

It does make sense and it's a good base to start off. I'll work on this and I'll leverage as well the middleware API which might be very useful for the admin part.

I'm going to also move this issue to the main repository themosis/framework as this project is the plugin boilerplate that consumes the core API.

jlambe commented 7 years ago

https://github.com/themosis/framework/issues/417