This document provides a comprehensive guide to Laravel Artisan commands...
1. Project Management Commands
php artisan list:
Description: Lists all available Artisan commands.
Usage:
php artisan list
Details: Displays a list of all the commands available in your Laravel application.
php artisan help Command:
Description: Displays help information for a specific command.
Usage:
php artisan help migrate
Details: Provides detailed help and options for a specific Artisan command.
php artisan env:
Description: Displays the current environment configuration.
Usage:
php artisan env
Details: Shows the environment your application is currently running in (e.g., local, production).
php artisan key:generate:
Description: Sets the application encryption key.
Usage:
php artisan key:generate
Details: Generates a new encryption key for your application.
php artisan serve:
Description:Starts a development web server on your local machine.
Usage:
php artisan serve
Details: This command launches a PHP development server on http://localhost:8000, allowing you to view your application in a web browser.
php artisan down:
Description:Puts your Laravel application into maintenance mode.
Usage:
php artisan down
Details: When your application is in maintenance mode, a custom maintenance page will be shown to all users, making it useful when performing updates or maintenance tasks.
php artisan up:
Description:Brings your Laravel application out of maintenance mode.
Usage:
php artisan up
Details: Restores access to your application, taking it out of maintenance mode and allowing users to interact with it again.
php artisan tinker:
Description:Brings your Laravel application out of maintenance mode.
Usage:
php artisan tinker
Details: Tinker is a powerful REPL (Read-Eval-Print Loop) that allows you to interact with your Laravel application in real-time. You can experiment with your application's models, jobs, and other features without affecting the production environment.
2. Database Commands
php artisan migrate:
Description: Runs the database migrations.
Usage:
php artisan migrate
Details: Executes all pending migrations for your application.
php artisan migrate:refresh:
Description: Resets and re-runs all migrations.
Usage:
php artisan migrate:refresh
Details: Rolls back all migrations and then runs them again.
php artisan migrate:reset:
Description: Rolls back all migrations.
Usage:
php artisan migrate:reset
Details: Reverses all migrations in your application.
php artisan migrate:rollback:
Description: Rolls back the last database migration.
Usage:
php artisan migrate:rollback
Details: This command undoes the last batch of migrations, reverting your database to its previous state.
php artisan db:seed:
Description: Seeds the database with initial data.
Usage:
php artisan db:seed
Details: Runs the database seeders, populating your database with initial data defined in seeder classes.
php artisan db:wipe:
Description: Clears all tables in the database.
Usage:
php artisan db:wipe
Details: This command drops all tables, views, and types from the database, effectively wiping it clean.
php artisan schema:dump :
Description: Generates a database schema dump.
Usage:
php artisan schema:dump
Details: TCreates a SQL dump of the current database schema, which can be useful for version control or database migration.
3. Code Generation Commands
php artisan make:controller ControllerName:
Description: Creates a new controller.
Usage:
php artisan make:controller UserController
Details: Generates a new controller class with the specified name.
php artisan make:middleware MiddlewareName:
Description: Creates a new middleware class.
Usage:
php artisan make:middleware CheckAge
Details: Generates a new middleware class with the specified name.
php artisan make:request RequestName:
Description: Creates a new form request class.
Usage:
php artisan make:request StoreUserRequest
Details: Generates a new request class for handling form validation.
php artisan make:model:
Description: Generates a model class and migration.
Usage:
php artisan make:model {ModelName} --migration
Details: Creates a new Eloquent model and an associated migration file. Models represent the data in your application, and migrations manage the database structure.
php artisan make:command:
Description: Generates a command class.
Usage:
php artisan make:command {CommandName}
Details: Creates a new command class that can be executed from the command line. Custom commands are useful for automating repetitive tasks.
php artisan make:event:
Description: Generates an event class.
Usage:
php artisan make:event {EventName}
Details: Creates a new event class, which is used to signal that something has happened in the application, allowing other parts of the application to respond to it.
php artisan make:job:
Description: Generates a job class.
Usage:
php artisan make:job {JobName}
Details: Creates a new job class that can be dispatched to Laravel's job queue, allowing you to offload time-consuming tasks to be processed asynchronously.
php artisan make:listener:
Description: Generates a listener class.
Usage:
php artisan make:listener {ListenerName}
Details: Creates a new listener class, which is responsible for handling events that are fired within the application.
php artisan make:provider:
Description: Generates a service provider class.
Usage:
php artisan make:provider {ProviderName}
Details: Creates a new service provider class, which is used to bind services into the Laravel service container.
4. Testing Commands
php artisan test:
Description: Runs the tests for your application.
Usage:
php artisan test
Details: Executes all the test cases defined in your application.
php artisan make:test TestName:
Description: Creates a new test class.
Usage:
php artisan make:test UserTest
Details: Generates a new test class with the specified name.
5. Deployment Commands
php artisan queue:work:
Description: Processes jobs on the queue.
Usage:
php artisan queue:work
Details: Continuously processes jobs in the queue.
php artisan queue:listen:
Description: Listens to the queue and processes jobs.
Usage:
php artisan queue:listen
Details: Listens for new jobs on the queue and processes them.
php artisan schedule:run:
Description: Runs the scheduled commands.
Usage:
php artisan schedule:run
Details: Executes the scheduled tasks defined in your application.
php artisan deploy:
Description: Deploys the application to production.
Usage:
php artisan deploy
Details: This command automates the process of deploying your application to a production environment, handling tasks like clearing caches, migrating the database, and optimizing the application.
php artisan env:set APP_ENV production:
Description: Sets the application environment to "production".
Usage:
php artisan env:set APP_ENV production
Details: Changes the environment configuration to production, which is essential when deploying your application to a live server.
6. Cache Management Commands
php artisan cache:clear:
Description: Clears the application cache.
Usage:
php artisan cache:clear
Details: Removes all cached data from your application.
php artisan config:cache:
Description: Creates a cache file for faster configuration loading.
Usage:
php artisan config:cache
Details: Combines all configuration files into a single cache file.
php artisan route:cache:
Description: Creates a cache file for faster route registration.
Usage:
php artisan route:cache
Details: Combines all route definitions into a single cache file.
php artisan view:cache:
Description: Compiles all Blade templates.
Usage:
php artisan view:cache
Details: Compiles Blade templates into plain PHP code for better performance.
php artisan view:clear:
Description: Clears all compiled view files.
Usage:
php artisan view:clear
Details: Removes all compiled Blade templates.
7. Other Commands
php artisan optimize:
Description: Optimizes the framework for better performance.
Usage:
php artisan optimize
Details: Caches various parts of the framework for faster performance.
php artisan storage:link:
Description: Creates a symbolic link from public/storage to storage/app/public.
Usage:
php artisan storage:link
Details: Makes the storage files publicly accessible.
Post a Comment