GithubHelp home page GithubHelp logo

jeffersonsimaogoncalves / extended-routes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thedragoncode/extended-routes

1.0 1.0 0.0 165 KB

This helper extends the standard set of resource routing methods to work with SoftDeletes and other extends

License: MIT License

PHP 100.00%

extended-routes's Introduction

Extended Routes

This helper extends the standard set of resource routing methods to work with SoftDeletes and other extends.

extended routes

StyleCI Total Downloads Latest Stable Version Latest Unstable Version License

Installation

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.

Using

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

Copyright and License

This package was written with the participation of Maksim (Ellrion) Platonov under MIT License.

extended-routes's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.