Extender Resource Controllers

Asked

Viewed 93 times

3

I’m doing what I want in a way and I’m looking for alternatives or better ways to do it. I am using Resource Controllers in my application. I am also using softdelete in several models, so my routes are like this:

Route::get('users/deleted', array('uses' => 'UserController@trash'));
Route::put('users/{id}/restore', array('uses' => 'UserController@restore'));
Route::resource('users', 'UserController');

The first route is to display those that have been deleted. The second allows me to restore these deleted elements. The third maps traditional methods (create, Edit, update etc).

What happens is that since I have several controllers that work exactly the same way, I wonder if you have any way to tell the Standard that when I have a Resource Controller, the Restore and Trash methods work in the requests in the above patterns.

Is it possible? Or can you do it better than the one I’m doing?

1 answer

1

Based on this post from forum do Laravel you can solve this.

class MyRouter extends \Laravel\Routing\Router {}

app/config/app.php

'aliases'   => array( 
//--//
Route'  => 'MyRoute'
//--//
);

I haven’t tested the solution to know if it works 100%, but I believe you can create all the methods you want like this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.