serverfireteam / panel

An easily configurable admin panel for Laravel applications.
MIT License
427 stars 144 forks source link

Quickedit publish/unpublish from grid #325

Closed lbm-services closed 7 years ago

lbm-services commented 7 years ago

Hi, I wanted to add a toggle-publish-link in my grid view. I added this to my template:

@if ($cell->name == 'published')
                    <a href="{!! url('panel/'.$current_entity.'/togglePublished') !!}?id={!! $row->data->id !!}">{!! $cell->value !!}</a>
@endif

and added a togglePublish-method to my controller.

   public function togglePublished(Request $request)
    {
        $id = $request->get('id');
        Models\blog_posts::updatePublished($id);
        return redirect('panel/blog_posts/all');

    }

Now I get Type error: Argument 1 passed to blog\Http\Controllers\blog_postsController::togglePublished() must be an instance of Illuminate\Http\Request, string given

Somehow all crudcontroller methods get the entity name as an argument and nothing else. How can I get the row id from query string?

lbm-services commented 7 years ago

I solved it like this:

 public function togglePublished($entity)
    {
        $id = \Request()->query('id');
        Models\blog_posts::updatePublished($id);
        return redirect('panel/blog_posts/all');
    }

But why is the entity passed as an argument, if the controller is for a defined entity, it could be a private property as well, I think.

AlirezaAlgo commented 7 years ago

@lbm-services thank you for your solution, if you think we need to change the code please send a pull request