LaravelRUS / SleepingOwlAdmin

🦉 Administrative interface builder for Laravel (Laravel admin)
http://sleepingowladmin.ru/
MIT License
805 stars 217 forks source link

Set Custom Controller for each Model configuration on "Display" and "Create and Edit" #32

Closed denistorresan closed 8 years ago

denistorresan commented 8 years ago

Hello, there's a way to set a specific controller that override the standard controller for a specific model? I mean something like this:

// /app/Admin/Contact3.php

$model->onDisplay(function () {
    $display = AdminDisplay::table();
    ...
    $display->setController("/App/Http/Controller/MyCustomContact3Controller@list");
   ...
}

$model->onCreateAndEdit(function($id = null) {
    $display = AdminDisplay::tabbed();
    ...
    $display->setController("/App/Http/Controller/MyCustomContact3Controller@save");
}

I think it's very useful for making custom behaviour on list or save (IE: elaborate data before save or call background shell commands etc..).

butschster commented 8 years ago

Hi.

Maybe set global controller class?

AdminSection::registerModel(Contact3::class, function (ModelConfiguration $model) {

     $model->setControllerClass(\App\Http\Controller\MyCustomContact3Controller::class);

     $model->onDisplay(function () { ... });

});

And you will create controller

class MyCustomContact3Controller extends \SleepingOwl\Admin\Http\Controllers\AdminController 
{
    public function getCreate(ModelConfiguration $model)
    {

        ...

        // Custom logic

        ...

        return $this->render($model, $create);
    }
}
denistorresan commented 8 years ago

Hello, great! I think in this way it's very easy to customize logic! Great work, thank you!

butschster commented 8 years ago

You are welcome! :) Try new release https://github.com/LaravelRUS/SleepingOwlAdmin/releases/tag/4.16.86-beta