search
HomePHP FrameworkLaravelWhat is artisan in Laravel

What is artisan in Laravel

Jan 06, 2022 pm 02:35 PM
artisanlaravel

artisan is the name of the command line tool that comes with Laravel. It provides some commands that are helpful for application development; artisan is driven by the powerful Symfony Console component. Developers can use the list command to view all Available Artisan commands.

What is artisan in Laravel

The operating environment of this article: Windows 7 system, Laravel version 5.7, Dell G3 computer.

What is artisan in Laravel?

Detailed explanation of the use of artisan tool (command) in laravel

artisan tool, first of all, this is a php file, which is placed at the root of our laravel framework Table of Contents

  • Artisan Tool Introduction

Artisan is the name of the command line tool that comes with Laravel. It provides some commands that are helpful for your application development. It is powered by the powerful Symfony Console component. In order to view all available Artisan commands, you can use the list command to list them:

Execute in the scriptphp artisan listYou can view all commands

Then Those who are familiar with Linux know that no matter what command there is, there is a help command. When running, suddenly, if you forget, you can execute the help command to check the command we need. Similarly, you can also execute help in the laravel framework. Command to view such as:
php artisan help migrate

  • Use artisan tool to create a controller

Understand tp Framework students will know that if you create a controller, you need to handwrite, namespace, inherited classes, etc.
Then in laravel, you can also use artisan tools to execute, such as creating a MsgController
php artisan make:controller MsgController
After execution, 'app\http\Controllers' will have one more MsgController, and methods are also prepared to add, delete, modify, check, etc. What if you don't need it? What? It's very simple. One is to delete it directly, and the other is to use commands to generate a blank controller, such as:
php artisan make:controller --plain

However, some students will encounter In this case, for example, a project is divided into frontend and backend, and the corresponding controllers also need to be placed in different directories. How to deal with this? If you use artisan tools? For example, create an Admin\GoodsController

php artisan make:controller Admin\GoodsController
The premise is that the Admin folder has been created under App\Http\Controllers in the laravel project. After execution, you will find that there are more GoodsController files under admin. Open it , it is found that the namespace is also automatically organized;
This command instruction verifies the flexibility of the laravel framework, developers can specify it at will;

  • Use the artisan tool to create the model

As programmers, while developing projects, we need to operate the database, which must be related to the model. So how to use the artisan tool to create a model? And controller, Much the same, such as creating a Msg model

php artisan make:model Msg
In laravel, it is placed in the App directory by default. If you want to define your own folder, it is the same as the controller. We specify it. directory, but it should be noted that the namespace needs to be changed

  • Use the artisan tool to view the route

In the laravel framework, If you want to respond to the method in the controller in the browser, then you only need to specify the route in App\routes.php, but if we use resource routing, we only need to specify a route, and it Many methods are also directly generated, but we cannot see them, so what should we do?
php artisan route:list
Use this command to view all routes

Use artisan tool to create middleware
First of all, in laravel, middleware is also a very convenient thing, so what is middleware?
The simple understanding is that middleware can be placed in our controller. Execute before or after to affect the execution result.
Anyone who has used the laravel framework and done projects knows that every time a post is submitted, a Token error will be reported. The solution is to add
{ !!csrf_field()!!}, but what is the root cause?
In the problem of app\http\middleware\VerifyCsrfToken.php, send this middleware globally, every time It will be verified when submitting the post;

How to generate a middleware?

php artisan make:middleware EmailMiddleware
The execution will be, Find

in the middleware folder. The latest five Laravel video tutorials (recommended)

The above is the detailed content of What is artisan in Laravel. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Full-Stack Development with Laravel: Managing APIs and Frontend LogicFull-Stack Development with Laravel: Managing APIs and Frontend LogicApr 28, 2025 am 12:22 AM

In Laravel full-stack development, effective methods for managing APIs and front-end logic include: 1) using RESTful controllers and resource routing management APIs; 2) processing front-end logic through Blade templates and Vue.js or React; 3) optimizing performance through API versioning and paging; 4) maintaining the separation of back-end and front-end logic to ensure maintainability and scalability.

Lost in Translation: Cultural Nuances and Misunderstandings in Distributed TeamsLost in Translation: Cultural Nuances and Misunderstandings in Distributed TeamsApr 28, 2025 am 12:22 AM

Totackleculturalintricaciesindistributedteams,fosteranenvironmentcelebratingdifferences,bemindfulofcommunication,andusetoolsforclarity.1)Implementculturalexchangesessionstosharestoriesandtraditions.2)Adjustcommunicationmethodstosuitculturalpreference

Measuring Connection: Analytics and Insights for Remote Communication EffectivenessMeasuring Connection: Analytics and Insights for Remote Communication EffectivenessApr 28, 2025 am 12:16 AM

Toassesstheeffectivenessofremotecommunication,focuson:1)Engagementmetricslikemessagefrequencyandresponsetime,2)Sentimentanalysistogaugeemotionaltone,3)Meetingeffectivenessthroughattendanceandactionitems,and4)Networkanalysistounderstandcommunicationpa

Security Risks in Distributed Teams: Protecting Data in a Remote WorldSecurity Risks in Distributed Teams: Protecting Data in a Remote WorldApr 28, 2025 am 12:11 AM

Toprotectsensitivedataindistributedteams,implementamulti-facetedapproach:1)Useend-to-endencryptionforsecurecommunication,2)Applyrole-basedaccesscontrol(RBAC)tomanagepermissions,3)Encryptdataatrestwithkeymanagementtools,and4)Fosterasecurity-consciousc

Beyond Email: Exploring Modern Communication Platforms for Remote CollaborationBeyond Email: Exploring Modern Communication Platforms for Remote CollaborationApr 28, 2025 am 12:03 AM

No, emailisnotthebostforremotecollaborationToday.Modern platformlack, Microsoft teams, Zoom, ASANA, AndTrelloFhertreal-Time Communication, Project management, Andintegrationfeaturesthancteamworkandefficiency.

Collaborative Document Editing: Streamlining Workflow in Distributed TeamsCollaborative Document Editing: Streamlining Workflow in Distributed TeamsApr 27, 2025 am 12:21 AM

Collaborative document editing is an effective tool for distributed teams to optimize their workflows. It improves communication and project progress through real-time collaboration and feedback loops, and common tools include Google Docs, Microsoft Teams, and Notion. Pay attention to challenges such as version control and learning curve when using it.

How long will the previous Laravel version be supported?How long will the previous Laravel version be supported?Apr 27, 2025 am 12:17 AM

ThepreviousversionofLaravelissupportedwithbugfixesforsixmonthsandsecurityfixesforoneyearafteranewmajorversion'srelease.Understandingthissupporttimelineiscrucialforplanningupgrades,ensuringprojectstability,andleveragingnewfeaturesandsecurityenhancemen

Leveraging Laravel's Features for Both Frontend and Backend DevelopmentLeveraging Laravel's Features for Both Frontend and Backend DevelopmentApr 27, 2025 am 12:16 AM

Laravelcanbeeffectivelyusedforbothfrontendandbackenddevelopment.1)Backend:UtilizeLaravel'sEloquentORMforsimplifieddatabaseinteractions.2)Frontend:LeverageBladetemplatesforcleanHTMLandintegrateVue.jsfordynamicSPAs,ensuringseamlessfrontend-backendinteg

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function