0

I want to add some default routes for the whole model, since my models all use these methods, is there a way to do this? Specifically the methods: trash(), restore(), forceDelete(), removeAll(), restoreAll(), forceDeleteAll();

`

<?php

namespace App\Http\Controllers\Article;

use App\Http\Controllers\Controller;

class ArticleController extends Controller
{
    public function index(){}

    public function create(){}

    public function store(ArticleRequest $request){}

    public function update(ArticleRequest $request, $id){}

    public function destroy($id){}

    public function trash(){}

    public function restore($id){}

    public function forceDelete($id)v

    public function removeAll(Request $request){}

    public function restoreAll(Request $request){}

    public function forceDeleteAll(Request $request){}

}

`

Thanks!

ChungND
  • 131
  • 1
  • 6
  • Does this answer your question? [Add new methods to a resource controller in Laravel](https://stackoverflow.com/questions/16661292/add-new-methods-to-a-resource-controller-in-laravel) – Rémy Dec 03 '22 at 00:12
  • do you want more default routes defined for `Route::resource`? – lagbox Dec 03 '22 at 04:22
  • The Stubs are in the `vendor/laravel/framework/src/Illuminate/Routing/Console/stubs`. It is not advised to change these as they will get overwritten by updates. – john Dec 06 '22 at 17:06

1 Answers1

0

You can customise the stubs that are used when using artisan make commands by executing the artisan stub:publish command. Then customise the controller stub in stubs/controller.stub (or any other stub) to your needs.

More info here: https://laravel.com/docs/9.x/artisan#stub-customization

Roj Vroemen
  • 1,853
  • 12
  • 11
  • This only makes the method available when I create the controller using the command line, but I still have to declare the Route, is there a way to make my route default for those methods as well, when using Route::resource ? – ChungND Dec 04 '22 at 21:43