How to Create Controller in Laravel 8 By using Command ?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share
How to Create Controller in Laravel 8

Hello Dev’s
Today in this blog, I will give a example of how to create controller in laravel 8 by using command. From here we will learn about How to Create Controller in Laravel 8 application using Command. Here i will give you more examples of artisan command to create controller in laravel 8.

Here you can see a list of examples of artisan command to create controller in laravel 8 application.

Example 1:

php artisan make:controller PostController

->It will create a simple controller class name

->It will also create a file by following path.

1.controller:-

app/Http/Controllers/PostController.php

Example 2.

php artisan make:controller PostController --resource

->It will also create controller name with file.

->It will create following methods as resource controller as PostController:

index,create,store,show,edit,update,destroy

->It Will also passing the argument as –resource.

->It will also create file a following path.

1.controller:-

app/Http/Controllers/PostController.php

Example 3.

php artisan make:controller PostController --resource --model=Post

->It will create controller name and model with file.

->It will also create following methods as resource controller as PostController:

index,create,store,show,edit,update,destroy

->It Will passing the argument as –resource and –model.

->It will also create fille following path.

1.controller:-

app/Http/Controllers/PostController.php

2.model:-

app/Post.php

Example 4.

php artisan make:controller PostController --api

->It will create api controller name with file.

->It will also create following methods as resource controller as PostController:

index,create,store,show,edit,update,destroy

->It Will passing the argument as –api.

->It will also create fille following path.

1.controller:-

app/Http/Controllers/PostController.php

Example 5.

php artisan make:controller PostController --invokable

->It will create api controller name with file.

->It will also create following methods as resource controller as PostController:

__invoke

->It Will passing the argument as –invokable.

->It will also create fille following path.

1.controller:-

app/Http/Controllers/PostController.php

Example 6.

php artisan make:controller PostController --parent=Post

->It will create controller name and model with file.

->It will also create following methods as resource controller as PostController:

index,create,store,show,edit,update,destroy

->It Will passing the argument as –parent.

->It will also create fille following path.

1.controller:-

app/Http/Controllers/PostController.php

2.model:-

app/Post.php

->It will Call method in all require parameter

Read Also : How to run laravel project without php artisan serve command ?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →