Laravel Most Useful Commands

Laravel Most Useful Commands

 2,764 total views,  5 views today

Hello everyone, Welcome to blog.sunnydoshi.in. Laravel packs a Artisan that will make your life as a developer so much easier! This tutorial will help you to understand the Laravel application commands. There are so many useful commands in laravel php, But here I list most common useful commands which use regular for laravel application development. If you’re not familiar with Laravel or Other CLI base framework, then you might not be aware of Artisan and other related to php and laravel commands.

Suggested tutorials:

Log in to the system running your Laravel application and open a terminal. Then navigate to your Laravel application code. Here you can issue the commands as followings:

Laravel PHP Command (Terminal)

Check Laravel Version by CLI

$ php artisan --version

Check Laravel Version Using File Structure

From laravel webroot directory: /vendor/laravel/framework/src/Illuminate/Foundation/Application.php
There is line: const VERSION = '5.5.49';

If you want to delete (.env.example) file then use following command:

//rm <filename>
$ rm .env.example

$ php artisan serve (We need every time run this command for run the laravel project on browser, To overcome this we can create .bat file for this command. Using bat file just click on that and it will run automatically) Put that file in laravel project webroot directory. With the help of this file it’s also clear cache, route and view. To create .bat file check following steps:

For ex: We’ll create (laravebasicauth.bat) file. Put these line inside file and save with .bat extension (Here cd <directory path>):

cd d:\xampp\htdocs\laravebasicauth
d:
php artisan config:cache
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan serve
pause

To install all vendor dependencies and Laravel Framework

$ composer install

To generates a file called composer.lock which lists all your packages and the currently installed version updates.

$ composer update

To generate the new key to your .env file but not the app.php file.

$ php artisan key:generate

Clear Route Cache

$  php artisan route:clear

If your site’s error is related to cache, these two commands should fix it, AFTER the code is deployed and the .env file is created.

$ php artisan config:cache
$ php artisan config:clear

If you are uploading your files through GIT from your local machine then you can use the same command you are using in your local machine while you are connected to your live server using BASH or something like. You can use this as like you use locally. This will clear the application cache of the Laravel application.

$ php artisan cache:clear
$ php artisan route:cache

When you may need to clear compiled view files of your Laravel application. To clear compiled view files run the following command from the terminal.

$ php artisan view:clear

To display the domain, method, URI, name, action and middleware for the routes also includes in the generated table, Run the following command.

$ php artisan route:list

To migrate the migrations files to the database succssfully.

$ php artisan migrate

Clear Cache in Laravel (Browser)

Most of the shared hosting providers don’t provide SSH access to the systems. In that case, you can clear the Laravel cache by calling the URL in the browser. You can simply place the below code in your routes/web.php file of the Laravel application. Then access this URL in the browser to clear the cache of the Laravel application.

Route::get('/clear-cache', function() {
    Artisan::call('cache:clear');
    return "Cache is cleared";
});

Some command might be deprecated in some time, So also check on official documentation as well.

Official Documentation for the Artisan Console Commands can be found on the Laravel Artisan Console.

Official Documentation for the Migrations & Seeding Commands can be found on the Laravel Migrations & Seeding.

For Dingo API information check documentation Dingo API

For Seeder, I will upload specific tutorial on that.

Wrapping Up

I hope you learned something. If you did, feel free to share this article with a friend or on social media. Let me know if you have any other command suggestions, questions, feedback in the comment section or – either via Twitter or email.

Also, don’t hesitate to subscribe to newsletter if you like this article.

Share this post

Related posts