This helper extends the standard set of resource routing methods to work with SoftDeletes and other extends.
To get the latest version of Extended Routes
, simply require the project using Composer:
$ composer require andrey-helldar/extended-routes
Instead, you may of course manually update your require block and run composer update
if you so choose:
{
"require": {
"andrey-helldar/extended-routes": "^2.0"
}
}
For Laravel 5.4 - 6.x use ^1.0
version.
Add to BaseModel method
use Helldar\ExtendedRoutes\Routing\ModelBindingResolver;
use Illuminate\Database\Eloquent\SoftDeletes;
class Page extends Model
{
use SoftDeletes;
public function resolveRouteBinding($value, $field = null)
{
return (new ModelBindingResolver($this))
->resolve($value, $field);
}
}
or change extends of model:
use Helldar\ExtendedRoutes\Models\SoftDeletesModel;
//use Illuminate\Database\Eloquent\SoftDeletes;
class Foo extends SoftDeletesModel {
//use SoftDeletes; << need to remove conflicting trait.
}
or using trait:
use Helldar\ExtendedRoutes\Traits\SoftDeletesModel;
//use Illuminate\Database\Eloquent\SoftDeletes; << need to remove conflicting trait.
class Foo extends Model {
use SoftDeletesModel;
}
and for some model Foo with SoftDeletes trait we can add routes:
app('router')->apiRestorableResource('foos', 'FoosController');
// or
Route::apiRestorableResource('foos', 'FoosController');
Method | URI | Name | Action | Middleware |
---|---|---|---|---|
GET/HEAD | api/foos | foos.index | App\Http\Controllers\FoosController@index | api |
POST | api/foos | foos.store | App\Http\Controllers\FoosController@store | api |
GET/HEAD | api/foos/trashed | foos.trashed | App\Http\Controllers\FoosController@trashed | api |
GET/HEAD | api/foos/{foo} | foos.show | App\Http\Controllers\FoosController@show | api |
PUT/PATCH | api/foos/{foo} | foos.update | App\Http\Controllers\FoosController@update | api |
DELETE | api/foos/{foo} | foos.destroy | App\Http\Controllers\FoosController@destroy | api |
POST | api/foos/{foo}/restore | foos.restore | App\Http\Controllers\FoosController@restore | api |
This package was written with the participation of Maksim (Ellrion) Platonov under MIT License.