laravel how to create controller with resource

In Laravel, you can create a controller with resource using the artisan command. Here are the steps:

  1. Open your terminal or command prompt and navigate to your Laravel project directory.

  2. Run the following command to create a new controller with resource:


php artisan make:controller YourControllerName --resource


  1. Replace "YourControllerName" with the name you want to give your new controller. The "--resource" flag tells Laravel to create a controller with the CRUD operations for a resource.

  2. After running the command, Laravel will generate a new controller in the "app/Http/Controllers" directory with the name you specified. It will include methods for the following CRUD operations:

    • index: Display a listing of the resource.
    • create: Show the form for creating a new resource.
    • store: Store a newly created resource in storage.
    • show: Display the specified resource.
    • edit: Show the form for editing the specified resource.
    • update: Update the specified resource in storage.
    • destroy: Remove the specified resource from storage.

    You can modify these methods to suit your needs.



That's it! You now have a new controller with resource in your Laravel project.

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...