If you are a web developer who uses Laravel, you must have heard of Laravel command. It is a powerful tool that can help you perform various coding tasks with ease. With Laravel command, you can perform repetitive tasks with just a few keystrokes, making your coding process more efficient and less time-consuming.
In this article, we will explore the world of Laravel command, its benefits, and how to use it. With Laravel command, you can perform tasks such as generating code, running tests, and even managing your application’s database.
Here are some examples of commonly used Laravel commands which help you:
Self Update
“composer self-update” is a command used in the PHP dependency manager, Composer. It updates the Composer application itself to the latest version available.
composer self-update
Create new Project
“composer create-project” is a command-line tool that streamlines the process of creating new projects and managing dependencies.
composer create-project --prefer-dist laravel/laravel myprojectName
Keep update
“composer update” is a command that updates all the packages and libraries in your PHP project to the latest available version, as defined in your composer.json file. It checks the package repository for updates and installs the latest version of all packages or the versions you specify.
composer update
Clear Cache
“php artisan cache:clear” is a Laravel command used to clear the application cache. Clearing cache removes all cached data and forces the application to fetch fresh data from the database, resulting in improved performance.
php artisan cache:clear
Remove Package
The composer remove command, it is used to remove a package from your project. When you install a package using Composer, it creates a composer.json file that lists all the dependencies of your project, including the packages you have installed. The composer.lock file is also created, which contains the exact versions of the packages installed. When you run composer remove vendor/package, Composer removes the specified package from your project and updates the composer.json and composer.lock files accordingly.
composer remove vendor/package
Make your Laravel project modular.
Are you a Laravel developer looking to create modular applications? Are you tired of maintaining large and complex monolithic codebases? If so, then creating modules in Laravel may be the solution you need. In this article, we’ll learn about some useful commands.
To create Module we’ll use “L5Modula“ package. L5Modular is an MIT licensed open source project. It has undergone extensive testing and has excellent code quality.
Structure of laravel module
Install new module package
The following command should be run at the root of your project using a bash prompt.
composer require artem-schander/l5-modular
Create Module
Using this command entire module can be generated.
php artisan make:module module_name
Ex: php artisan make:module Admin
Make controller into module
Using this command controller can be created.
php artisan make:module:controller MyControllerName
Ex: php artisan make:module:controller AdminController
Make Model into module
Using this command model can be generated.
php artisan make:module:model
Make Resource into module
A Model is created into a module via this command.
php artisan make:module:resource
Make Request into module
A Request is created into a module via this command.
php artisan make:module:request
Make Mail into module
A Request is created into a module via this command.
php artisan make:module:mail
Make Migration into Table in module
This command will create a new migration file in the database/migrations directory.Open the generated migration file in the database/migrations directory using a code editor. You’ll see an up method in the migration file.
php artisan make:module:migration create_users_table
php artisan make:module:migration create_users_table --table=users
Define the table schema within this method. Here’s an example of createing a “users” table
Schema::table('users', function (Blueprint $table) {
$table->id();
$table->string('first_name');
$table->string('last_name');
$table->string('email')->unique();
$table->tinyInteger('type')->default(2);
/* Users:0=>user, 1=>Admin, 2=>SuperAdmin */
$table->string('country_name');
$table->string('country_code');
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Make Migration into module
A Migration is created into a module via this command.
php artisan make:module:migration
Make Seeder into module
A Seeder is created into a module via this command.
php artisan make:module:seeder
Create Helper into module
A Helper is created into a module via this command.
php artisan make:module:helpers
Display all Module List
This command lists all modules.
php artisan module:list