phplaravellaravel-6laravel-resource

How can I automatically add conditions in the method of a resource controller in Laravel?


I am trying to add a if condition when resource auto generates.

When I run php artisan make:controller SomeController -r, I want to generate the following,

class SomeController extends Controller
{
    public function index()
    {
        if (Auth::user()->can('')){
           //
        }else{
           //
        }
    }
    public function create()
    {
        if (Auth::user()->can('')){
           //
        }else{
           //
        }
    }
    public function store(Request $request)
    {
        if (Auth::user()->can('')){
           //
        }else{
           //
        }
    }
    public function show($id)
    {
        if (Auth::user()->can('')){
           //
        }else{
           //
        }
    }
    public function edit($id)
    {
        if (Auth::user()->can('')){
           //
        }else{
           //
        }
    }
    public function update(Request $request, $id)
    {
        if (Auth::user()->can('')){
           //
        }else{
           //
        }
    }
    public function destroy($id)
    {
        if (Auth::user()->can('')){
           //
        }else{
           //
        }
    }
}

Solution

  • To do the above, go to terminal and

    When you run php artisan make:controller -r the next time, it will autogenerate the resource with the changes you made to the stub file.