Closed avifatal closed 8 years ago
Hi,
You can use custom controller for 1 and 3 questions
Example
AdminSection::registerModel(Contact3::class, function (ModelConfiguration $model) {
$model->setControllerClass(\App\Http\Controller\MyCustomContact3Controller::class);
$model->onDisplay(function () { ... });
});
And then you will create controller
class MyCustomContact3Controller extends \SleepingOwl\Admin\Http\Controllers\AdminController
{
public function deleteDestroy(ModelConfiguration $model, $id)
{
$item = $model->getRepository()->find($id);
if (is_null($item) || ! $model->isDeletable($item)) {
abort(404);
}
$model->fireDelete($id);
$model->getRepository()->delete($id);
...
// Your code
...
return redirect()->back()->with('success_message', $model->getMessageOnDelete());
}
}
Could you explain more about 2 and 4 questions
Hi, thanks for your time and for your quick answer!
Thanks again. Avi
class News extends Model {
protected static function boot()
{
parent::boot();
static::deleting(function (News $news) {
Mail::send(....);
});
}
}
But it is possitble to add events (callbacks) to controller CRUD methods.
Like this
$model->beforeCreate(...);
$model->afterCreate(...);
$model->beforeUpdate(...);
$model->afterUpdate(...);
$model->beforeSave(...);
$model->afterSave(...);
$model->beforeDelete(...);
$model->afterDelet(...);
3.
your example I assume intercept delete operation. How can create custom operation from client to server, for example I want in customer grid to have a button near the delete and update that will call to the server and execute custom function, for example: CloseAllTasks() or whatever I want to do in the server.
Display
// Display
$model->onDisplay(function () {
$display = AdminDisplay::table()
->setActions([
AdminColumn::action('CloseAllTasks', 'Export')
->setIcon('fa fa-share')
->setAction(route('admin.news.export'))
->usePost()
])
->setColumns([
AdminColumn::checkbox(), // Required for actions working
...
AdminColumn::link('title')->setLabel('Title'),
...
]);
return $display;
});
Route
Route::post('/news/export', ['as' => 'admin.news.export', function () {
return new \Illuminate\Http\JsonResponse([
'title' => 'Congratulation! You exported news.',
'news' => App\Model\News5::whereIn('id', Request::get('id', []))->get()
]);
}]);
https://github.com/LaravelRUS/SleepingOwlAdmin/releases/tag/4.17.88-beta
4 Yes. We plane to create a few demo apps with different functionality. 5 API is planned for the near future.
Thank you! all is good, just about question 5. Embedding now grid in a form is impossible?
Hi.
Now you can register events for section:
Example
// Registering event from section class
AdminSection::registerModel(News::class, function (ModelConfiguration $model) {
...
$model->updating(function(ModelConfiguration $model, Model $item) {
Mail::send(...);
});
...
});
// Registering from ServisProvider or bootstrap.php
app('events')->listen("sleeping_owl.section.creating: App\Model\News", function() {
// do something
});
// or
Event::listen("sleeping_owl.section.creating: App\Model\News", function() {
// do something
});
Hi, I want to try and use this product, I have some questions if I may.
Thanks!