sleeping-owl / admin

Administrative interface builder for Laravel
http://sleeping-owl.github.io/
MIT License
503 stars 259 forks source link

Mass deleting #201

Open alexander-zugan opened 9 years ago

alexander-zugan commented 9 years ago

How can i make Mass removal in Admin Panel ??

noxify commented 9 years ago

Hi,

this is very easy to implement.

For V.3 use this: http://sleeping-owl.github.io/v3/en/Displays.html --> Bulk Actions

What you have to do is the following:

$display->actions([
    Column::action('export')->value('Export')->icon('fa-share')->target('_blank')->callback(function ($collection)
    {
        dd('You are trying to export:', $collection->toArray());
    }),
    ...
]);

This is the example from the documentation, you have to change it to whatever you need...

Here is a short example:

Admin::model('App\Model')->title('Title')->display(function ()
{
    $display = AdminDisplay::datatables();

    $display->columns([
        Column::checkbox(),
        Column::string('id')->label('#'),
        //some other columns
    ]);

    $display->actions([
        Column::action('massdelete')->value('Massdelete')->icon('fa-trash')->callback(function ($collection)
        {
            foreach ($collection->toArray() as $key => $delete_item) {

                $item = App\Model::find($delete_item['id']);
                //http://laravel.com/docs/5.1/eloquent#deleting-models
                $item->delete();
            }
        }),
        //more actions
    ]);

    return $display;
}   

Hope this helps :)

alexander-zugan commented 9 years ago

Thanks ,but i use v2 ... It is possible to make for v2 ??

noxify commented 9 years ago

I don't know - but I didn't see any in the V2 documentation. Maybe @sleeping-owl can say something?

Otherwise - upgrade to V.3 :)

alexander-zugan commented 9 years ago

I very late saw the v3 version and now only on the following project I will use v3 . But now it is necessary to think up something for v2 ...

noxify commented 9 years ago

Maybe you can add the actions() function to v2: https://github.com/sleeping-owl/admin/blob/development/src/SleepingOwl/Admin/Display/DisplayTable.php#L192

I didn't work with V.2, don't know where to implement it in V.2 - sorry :(

alexander-zugan commented 9 years ago

V.2 has no Column::checkbox() ((

theravel commented 8 years ago

In current (latest) version displays functionality is missing. Is there any way to perform bulk operations?

alexander-zugan commented 8 years ago

Вот так можно $display->setActions([ AdminColumn::action('delete', ' Удалить')->setIcon('fa fa-share')->setAction(route('admin_massdelete'))->useGet(), ])

Ну, а в контроллер по указаному роуту, уже делаешь уделание или что тебе нужно