Best Way To Exclude Resourceful Functions In Laravel

Hello artisan, in this example i will explain that how to exclude function or method name in a resource controller in laravel. According to source code, method resource is not chainable in laravel, because it returns void

Sometimes we need to chain all resource controller together and need to exclude some function like show, destroy etc. In this case, what do you do to organize your route list? For that i am here to help you.

We can write our own class that extends Illuminate\Routing\Route and implement your resources method like that:

namespace App\Extends;

class Route extends Illuminate\Routing\Route {

   public function resources($routes, array $excepts) {
     foreach ($routes as $key => $value){
         $this->resource($key, $value)->except($excepts);



After doing that you need to bind class in your service provider like this:


public function register()
    $this->app->bind('Illuminate\Routing\Route', 'App\\Extends\\Route');


Now call resources in web.php like that:


    'cateories' => 'CategoryController',
    'posts' => 'PostController',
], ['show']);


Now laravel will exclude show method and route from your above resource controller. But from laravel 5.8 we can register many resource controllers at once by passing an array to the resources method:

    'photos' => 'PhotoController',
    'posts' => 'PostController'


And exclude method like that:



Hope it can help you.