“This is the 27th day of my participation in the Gwen Challenge in November. See details of the event: The Last Gwen Challenge in 2021”

In my last post, I shared a common Laravel utility class that I encapsulated and received several comments like this

Laravel can request()-> IP () directly to obtain the IP, and laravel has a plugin for Carbon to manipulate the time, and a Str::random() method to generate random strings.

What digg friends said made a lot of sense, and I reflected on it. In order to minimize this kind of thing, I should be familiar with Laravel’s common commands, familiar with the built-in functions of the framework, and avoid repeated wheel building and repeated encapsulation.

Here are some of the common commands I’ve compiled

Common commands

Artisan

PHP artisan --help OR -h // Print the version information of Laravel PHP artisan --version OR -v // Force the output of PHP artisan in ANSI format PHP artisan list // Cache view files for efficiency PHP artisan view:cache // Clear view file cache  php artisan view:clearCopy the code

Composer

Create a project

composer create-project laravel/laravel folder_name
Copy the code

Global installation

composer require global vendor/packages
Copy the code

List all extensions including version information

composer show
Copy the code

Environment

Check whether the current environment is Local

if (app()->environment('local')){}
Copy the code

Check whether the environment is Local or test…

if (app()->environment(['local', 'test'])){}
Copy the code

Log

The second argument supports passing in arrays without the need to concatenate data into the first argument via json_encode()

Log::info('info',array('context'=>'additional info'));
Copy the code

Obtain monolog instances

Log::getMonolog();
Copy the code

Adding listeners

Log::listen(function($level, $message, $context) {});
Copy the code

SQL query statement

Open the log

DB::connection()->enableQueryLog();
Copy the code

Gets an array of executed queries

DB::getQueryLog();
Copy the code

Request

Returns the IP address of the user

Request::ip();
Copy the code

Access to the Url: xxx.com/a/b

Request::url();
Copy the code

Get the Uri: xxx.com/a/b/?c=d

Request::getUri();
Copy the code

Get the original POST data

Request::instance()->getContent();
Copy the code

Welcome to the interactive

What common commands are welcome to discuss in the comments section

Hardcore articles recommended

PHP to Go mid 2021 summary

How do I receive an interface error at the first time? No need to test the girl to question whether you are not dead interface.

Git use actual combat: collaborative development of many people, emergency repair online bug Git operation guide.

Performance tuning reflection: Do not manipulate DB in a for loop

Performance tuning reflection: Do not operate on DB advanced versions in for loops

The last

👍🏻 : feel the harvest please point a praise to encourage!

🌟 : Collect articles, easy to look back!

💬 : Comment exchange, mutual progress!