Laravel Artisan commands
Here are the Laravel Artisan commands to create a migration, model, controller, view, and component:
1. Create a Migration
php artisan make:migration create_table_name_table
- Replace
create_table_name_table
with your table name, e.g.,create_products_table
.
2. Create a Model
php artisan make:model Product
- This creates a
Product.php
model insideapp/Models/
(Laravel 8+).
🔹 With Migration and Factory:
php artisan make:model Product -mf
-m
→ Create a migration file.-f
→ Create a factory file for database seeding.
🔹 With Controller:
php artisan make:model Product -mc
-c
→ Create a resource controller.
3. Create a Controller
php artisan make:controller ProductController
- This creates a controller at
app/Http/Controllers/ProductController.php
.
🔹 Create a Resource Controller:
php artisan make:controller ProductController --resource
- Adds methods like
index()
,show()
,store()
,update()
, anddestroy()
.
4. Create a Blade View
Blade views are not created with Artisan. Instead, manually create them inside resources/views/
.
Example:
touch resources/views/products/index.blade.php
5. Create a Component
php artisan make:component Alert
- This creates:
app/View/Components/Alert.php
(Component logic).resources/views/components/alert.blade.php
(Component Blade template).
Bonus: Create Everything at Once
For a Product feature (model, migration, controller, and factory):
php artisan make:model Product -mcrf
Let me know if you need more details! 🚀