[{"data":1,"prerenderedAt":1015},["ShallowReactive",2],{"series-\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsetting-up-your-laravel-project-structure-and-essentials":3,"series-context-\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api":803},{"id":4,"title":5,"body":6,"contentId":790,"date":791,"description":792,"extension":793,"github":794,"meetTheInstructor":794,"meta":795,"navigation":152,"part":63,"path":796,"rawbody":797,"robots":794,"schemaOrg":794,"seo":798,"seriesSlug":799,"sitemap":800,"stem":801,"subtitle":794,"topics":794,"__hash__":802},"series\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsetting-up-your-laravel-project-structure-and-essentials.md","Setting Up Your Laravel Project Structure and Essentials",{"type":7,"value":8,"toc":759},"minimark",[9,13,22,25,30,45,48,83,96,99,104,190,197,200,239,242,245,262,265,268,272,275,284,287,293,299,304,313,323,328,333,338,343,350,355,360,365,374,379,391,397,402,415,420,425,446,457,462,467,470,475,483,487,490,496,501,507,512,518,526,532,537,543,548,554,559,564,569,575,580,599,677,680,690,696,701,707,712,718,723,729,734,740,745,749,752,755],[10,11,12],"p",{},"Welcome to the Laravel part of this series! 👋",[10,14,15,16,21],{},"In the previous series, we set up a VitePress blog in ",[17,18,20],"a",{"href":19},"\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch","Create a Blog with VitePress and Vue.js from Scratch",". Now we are ready to build the Laravel API that will power its interactive features. You do not need to have read that series, but it provides useful context for what follows.",[10,23,24],{},"In this first article, we will create the Laravel project, explore its structure, and identify where the code we write throughout this series will live. By the end, you should feel comfortable finding your way around the application.",[26,27,29],"h2",{"id":28},"setting-up-the-project","Setting up the project",[31,32,35],"callout",{"color":33,"icon":34},"info","i-ph-info-duotone",[10,36,37,38,44],{},"This article does not cover installing Laravel itself. For that, refer to ",[17,39,43],{"href":40,"rel":41},"https:\u002F\u002Flaravel.com\u002Fdocs\u002F12.x\u002Finstallation",[42],"nofollow","the official documentation",".",[10,46,47],{},"One of Laravel's strengths is its CLI, which helps you create a new project quickly. Run the following command:",[49,50,56],"pre",{"className":51,"code":52,"filename":53,"language":54,"meta":55,"style":55},"language-bash shiki shiki-themes github-light github-light github-dark","laravel new mimram --pest # Mimram is the name of the project\n","terminal","bash","",[57,58,59],"code",{"__ignoreMap":55},[60,61,64,68,72,75,79],"span",{"class":62,"line":63},"line",1,[60,65,67],{"class":66},"snPdu","laravel",[60,69,71],{"class":70},"sIIMD"," new",[60,73,74],{"class":70}," mimram",[60,76,78],{"class":77},"sBjJW"," --pest",[60,80,82],{"class":81},"sCsY4"," # Mimram is the name of the project\n",[31,84,85],{"color":33,"icon":34},[10,86,87,88,91,92,95],{},"Starting with Laravel 12, the ",[57,89,90],{},"laravel new"," command no longer prompts for the testing framework. The ",[57,93,94],{},"--pest"," flag sets up Pest automatically.",[10,97,98],{},"The setup should look like this:",[31,100,101],{"color":33,"icon":34},[10,102,103],{},"For this article, I'm using version 12.x of Laravel.",[49,105,110],{"className":106,"code":107,"filename":108,"language":109,"meta":55,"style":55},"language-txt shiki shiki-themes github-light github-light github-dark","   _                               _\n  | |                             | |\n  | |     __ _ _ __ __ ___   _____| |\n  | |    \u002F _` |  __\u002F _` \\ \\ \u002F \u002F _ \\ |\n  | |___| (_| | | | (_| |\\ V \u002F  __\u002F |\n  |______\\__,_|_|  \\__,_| \\_\u002F \\___|_|\n\n ┌ Which starter kit would you like to install? ────────────────┐\n │ › ● None                                                     │\n │   ○ React                                                    │\n │   ○ Vue                                                      │\n │   ○ Livewire                                                 │\n └──────────────────────────────────────────────────────────────┘\n","Example","txt",[57,111,112,117,123,129,135,141,147,154,160,166,172,178,184],{"__ignoreMap":55},[60,113,114],{"class":62,"line":63},[60,115,116],{},"   _                               _\n",[60,118,120],{"class":62,"line":119},2,[60,121,122],{},"  | |                             | |\n",[60,124,126],{"class":62,"line":125},3,[60,127,128],{},"  | |     __ _ _ __ __ ___   _____| |\n",[60,130,132],{"class":62,"line":131},4,[60,133,134],{},"  | |    \u002F _` |  __\u002F _` \\ \\ \u002F \u002F _ \\ |\n",[60,136,138],{"class":62,"line":137},5,[60,139,140],{},"  | |___| (_| | | | (_| |\\ V \u002F  __\u002F |\n",[60,142,144],{"class":62,"line":143},6,[60,145,146],{},"  |______\\__,_|_|  \\__,_| \\_\u002F \\___|_|\n",[60,148,150],{"class":62,"line":149},7,[60,151,153],{"emptyLinePlaceholder":152},true,"\n",[60,155,157],{"class":62,"line":156},8,[60,158,159],{}," ┌ Which starter kit would you like to install? ────────────────┐\n",[60,161,163],{"class":62,"line":162},9,[60,164,165],{}," │ › ● None                                                     │\n",[60,167,169],{"class":62,"line":168},10,[60,170,171],{}," │   ○ React                                                    │\n",[60,173,175],{"class":62,"line":174},11,[60,176,177],{}," │   ○ Vue                                                      │\n",[60,179,181],{"class":62,"line":180},12,[60,182,183],{}," │   ○ Livewire                                                 │\n",[60,185,187],{"class":62,"line":186},13,[60,188,189],{}," └──────────────────────────────────────────────────────────────┘\n",[10,191,192,193,196],{},"Since we have an existing frontend, select the ",[57,194,195],{},"None"," option.",[10,198,199],{},"Next, it will ask about the database our application should use.",[49,201,203],{"className":106,"code":202,"filename":108,"language":109,"meta":55,"style":55}," ┌ Which database will your application use? ───────────────────┐\n │ › ● SQLite                                                   │\n │   ○ MySQL                                                    │\n │   ○ MariaDB                                                  │\n │   ○ PostgreSQL                                               │\n │   ○ SQL Server (Missing PDO extension)                       │\n └──────────────────────────────────────────────────────────────┘\n",[57,204,205,210,215,220,225,230,235],{"__ignoreMap":55},[60,206,207],{"class":62,"line":63},[60,208,209],{}," ┌ Which database will your application use? ───────────────────┐\n",[60,211,212],{"class":62,"line":119},[60,213,214],{}," │ › ● SQLite                                                   │\n",[60,216,217],{"class":62,"line":125},[60,218,219],{}," │   ○ MySQL                                                    │\n",[60,221,222],{"class":62,"line":131},[60,223,224],{}," │   ○ MariaDB                                                  │\n",[60,226,227],{"class":62,"line":137},[60,228,229],{}," │   ○ PostgreSQL                                               │\n",[60,231,232],{"class":62,"line":143},[60,233,234],{}," │   ○ SQL Server (Missing PDO extension)                       │\n",[60,236,237],{"class":62,"line":149},[60,238,189],{},[10,240,241],{},"For this project, choose SQLite.",[10,243,244],{},"SQLite is a C library that stores data in a single database file on disk, making it portable and low-maintenance. It may not fit every use case, but it is an excellent choice for a simple blog that will not experience heavy traffic.",[31,246,247],{"color":33,"icon":34},[10,248,249,250,255,256,261],{},"To learn more about SQLite, I recommend ",[17,251,254],{"href":252,"rel":253},"https:\u002F\u002Fhighperformancesqlite.com\u002F",[42],"High Performance SQLite"," by ",[17,257,260],{"href":258,"rel":259},"https:\u002F\u002Fx.com\u002Faarondfrancis",[42],"Aaron Francis",". It is an excellent series for mastering SQLite.",[10,263,264],{},"Finally, say yes when asked whether you want to install the JavaScript dependencies and build the assets.",[10,266,267],{},"Perfect! We now have a fresh Laravel project in which to build our API.",[26,269,271],{"id":270},"project-structure","Project structure",[10,273,274],{},"Here's the project structure we will be working with:",[49,276,282],{"className":277,"code":279,"filename":280,"language":281,"meta":55},[278],"language-text","├── app\n│   ├── Http\u002F\n│   ├── Models\u002F\n│   └── Providers\u002F\n├── bootstrap\n│   ├── app.php\n│   └── cache\u002F\n├── config\n│   ├── app.php\n│   ├── database.php\n│   └── mail.php\n├── database\n│   ├── migrations\u002F\n│   ├── factories\u002F\n│   └── seeders\u002F\n├── public\n│   ├── index.php\n│   ├── css\u002F\n│   └── js\u002F\n├── resources\n│   ├── views\u002F\n│   ├── css\u002F\n│   └── js\u002F\n├── routes\n│   ├── web.php\n│   └── api.php\n├── storage\n│   ├── app\u002F\n│   ├── framework\u002F\n│   └── logs\u002F\n├── tests\n│   ├── Feature\u002F\n│   └── Unit\u002F\n└── vendor\n","Laravel Project Structure","text",[57,283,279],{"__ignoreMap":55},[10,285,286],{},"Let's dive into all the folders and files.",[288,289,291],"h3",{"id":290},"app",[57,292,290],{},[10,294,295,296,298],{},"The ",[57,297,290],{}," folder houses the core code of your application, including controllers, models, and services. It is the heart of the project and where you will spend most of your time coding.",[288,300,302],{"id":301},"bootstrap",[57,303,301],{},[10,305,295,306,308,309,312],{},[57,307,301],{}," folder contains files that initialize the application. It includes ",[57,310,311],{},"app.php",", which creates and configures the application.",[10,314,315,316,319,320,44],{},"The folder also contains the ",[57,317,318],{},"providers.php"," file, which loads the service providers. A service provider registers services, routes, and Laravel extensions such as macros and helpers. Every Laravel package has a service provider as its entry point, and your application providers live in ",[57,321,322],{},"app\u002FProviders",[288,324,326],{"id":325},"config",[57,327,325],{},[10,329,295,330,332],{},[57,331,325],{}," folder contains all the configuration files. Here, you can find settings for the database, mail, cache, and more.",[288,334,336],{"id":335},"database",[57,337,335],{},[10,339,295,340,342],{},[57,341,335],{}," folder stores database migrations, model factories, and seeders. Migrations version-control your database schema. Model factories generate test data conveniently, and seeders populate your database, often by using those factories.",[10,344,345,346,349],{},"Model factories relate to models located in the ",[57,347,348],{},"app\u002FModels"," folder.",[288,351,353],{"id":352},"node_modules",[57,354,352],{},[10,356,295,357,359],{},[57,358,352],{}," folder contains the JavaScript dependencies installed by npm, pnpm, or yarn. It is generated automatically and should not be committed to version control.",[288,361,363],{"id":362},"public",[57,364,362],{},[10,366,295,367,369,370,373],{},[57,368,362],{}," folder stores the front controller and public assets such as JavaScript, CSS, and images. It is the directory served by the web server. The ",[57,371,372],{},"index.php"," file is the application's entry point and routes incoming requests to Laravel.",[288,375,377],{"id":376},"resources",[57,378,376],{},[10,380,295,381,383,384,387,388,44],{},[57,382,376],{}," folder contains view files and raw assets such as CSS and JavaScript. In Laravel, views are PHP files called Blade templates. Blade provides an elegant syntax for PHP code and directives such as ",[57,385,386],{},"@if"," and ",[57,389,390],{},"@foreach",[10,392,393,394,349],{},"Raw assets are compiled by Vite and stored in the ",[57,395,396],{},"public\u002Fbuild",[288,398,400],{"id":399},"routes",[57,401,399],{},[10,403,295,404,406,407,410,411,414],{},[57,405,399],{}," folder holds the application's routes. It includes web routes, API routes, and console routes. Each file manages a specific type of route: ",[57,408,409],{},"web.php"," handles browser-facing routes, while ",[57,412,413],{},"api.php"," handles API routes.",[288,416,418],{"id":417},"storage",[57,419,417],{},[10,421,295,422,424],{},[57,423,417],{}," folder contains compiled Blade templates, file-based sessions, caches, logs, and other framework-generated files. It is divided into:",[426,427,428,434,440],"ol",{},[429,430,431,433],"li",{},[57,432,290],{},": Application-generated files.",[429,435,436,439],{},[57,437,438],{},"framework",": Framework-generated files.",[429,441,442,445],{},[57,443,444],{},"logs",": Application log files.",[10,447,448,449,452,453,456],{},"Look for the ",[57,450,451],{},"laravel.log"," file in ",[57,454,455],{},"storage\u002Flogs"," for error logs and stack traces.",[288,458,460],{"id":459},"tests",[57,461,459],{},[10,463,295,464,466],{},[57,465,459],{}," folder houses automated tests. Laravel includes Pest, a testing framework built on PHPUnit, for writing unit and feature tests. Testing ensures that your application behaves as expected and helps prevent regressions.",[10,468,469],{},"Throughout this series, we will write tests for our application, showcasing Laravel's ease of use in test writing.",[288,471,473],{"id":472},"vendor",[57,474,472],{},[10,476,295,477,479,480,482],{},[57,478,472],{}," folder holds all PHP dependencies, automatically generated by Composer. It is akin to the ",[57,481,352],{}," folder for JavaScript but for PHP.",[288,484,486],{"id":485},"root-files","Root files",[10,488,489],{},"Here's a list of files in the project root:",[288,491,493],{"id":492},"editorconfig",[57,494,495],{},".editorconfig",[10,497,295,498,500],{},[57,499,495],{}," file helps maintain consistent coding styles for multiple developers across editors and IDEs. It defines styles like indentation, line endings, and character encoding.",[288,502,504],{"id":503},"env",[57,505,506],{},".env",[10,508,295,509,511],{},[57,510,506],{}," file contains environment-specific configuration values, allowing you to configure the application without changing its code. It may include sensitive details such as database credentials and API keys.",[288,513,515],{"id":514},"envexample",[57,516,517],{},".env.example",[10,519,295,520,522,523,525],{},[57,521,517],{}," file is a template for ",[57,524,506],{},", providing the values needed to create a local configuration. Commit this file to version control so other developers know which variables are available.",[288,527,529],{"id":528},"gitattributes",[57,530,531],{},".gitattributes",[10,533,295,534,536],{},[57,535,531],{}," file defines attributes for paths in your repository, controlling Git's handling of line endings, merge strategies, and other behaviors for specific files or directories.",[288,538,540],{"id":539},"gitignore",[57,541,542],{},".gitignore",[10,544,295,545,547],{},[57,546,542],{}," file specifies files and directories Git should ignore, preventing sensitive data and unnecessary files from being committed.",[288,549,551],{"id":550},"readmemd",[57,552,553],{},"README.md",[10,555,295,556,558],{},[57,557,553],{}," file provides a project overview, covering setup, usage, and other essential details. It's often the first reference for new developers on the project.",[288,560,562],{"id":561},"artisan",[57,563,561],{},[10,565,295,566,568],{},[57,567,561],{}," file is Laravel's command-line interface. It provides commands for developing the application, running migrations, generating code, and executing tests.",[288,570,572],{"id":571},"composerjson",[57,573,574],{},"composer.json",[10,576,295,577,579],{},[57,578,574],{}," file is Composer's configuration file. It lists PHP dependencies and project metadata such as the project name and description.",[10,581,582,583,586,587,590,591,594,595,598],{},"This file includes a ",[57,584,585],{},"scripts"," key for running ",[57,588,589],{},"composer run"," commands. For instance, ",[57,592,593],{},"composer run test"," executes application tests. Among these scripts, the ",[57,596,597],{},"dev"," script launches development necessities:",[49,600,602],{"className":51,"code":601,"filename":574,"language":54,"meta":55,"style":55},"npx concurrently -c \\\"#93c5fd,#c4b5fd,#fb7185,#fdba74\\\" \\\"php artisan serve\\\" \\\"php artisan queue:listen --tries=1\\\" \\\"php artisan pail --timeout=0\\\" \\\"npm run dev\\\" --names=server,queue,logs,vite\n",[57,603,604],{"__ignoreMap":55},[60,605,606,609,612,615,618,621,624,626,629,632,635,637,639,641,643,646,649,651,653,655,658,661,663,666,669,672,674],{"class":62,"line":63},[60,607,608],{"class":66},"npx",[60,610,611],{"class":70}," concurrently",[60,613,614],{"class":77}," -c",[60,616,617],{"class":77}," \\\"",[60,619,620],{"class":70},"#93c5fd,#c4b5fd,#fb7185,#fdba74",[60,622,623],{"class":77},"\\\"",[60,625,617],{"class":77},[60,627,628],{"class":70},"php",[60,630,631],{"class":70}," artisan",[60,633,634],{"class":70}," serve",[60,636,623],{"class":77},[60,638,617],{"class":77},[60,640,628],{"class":70},[60,642,631],{"class":70},[60,644,645],{"class":70}," queue:listen",[60,647,648],{"class":77}," --tries=1\\\"",[60,650,617],{"class":77},[60,652,628],{"class":70},[60,654,631],{"class":70},[60,656,657],{"class":70}," pail",[60,659,660],{"class":77}," --timeout=0\\\"",[60,662,617],{"class":77},[60,664,665],{"class":70},"npm",[60,667,668],{"class":70}," run",[60,670,671],{"class":70}," dev",[60,673,623],{"class":77},[60,675,676],{"class":77}," --names=server,queue,logs,vite\n",[10,678,679],{},"Laravel is more than a single process during development. The web server handles requests, the Vite server serves assets, and the queue and log processes handle their respective tasks.",[10,681,295,682,685,686,689],{},[57,683,684],{},"composer run dev"," command launches these processes in parallel using the ",[57,687,688],{},"concurrently"," npm package.",[288,691,693],{"id":692},"composerlock",[57,694,695],{},"composer.lock",[10,697,295,698,700],{},[57,699,695],{}," file, generated by Composer, locks dependencies to specific versions and makes installations reproducible. Commit this file to version control.",[288,702,704],{"id":703},"phpunitxml",[57,705,706],{},"phpunit.xml",[10,708,295,709,711],{},[57,710,706],{}," file configures PHPUnit, including its test suites, bootstrap file, and environment options.",[288,713,715],{"id":714},"viteconfigjs",[57,716,717],{},"vite.config.js",[10,719,295,720,722],{},[57,721,717],{}," file configures Vite, Laravel's frontend build tool, including the JavaScript and CSS entry points.",[288,724,726],{"id":725},"packagejson",[57,727,728],{},"package.json",[10,730,295,731,733],{},[57,732,728],{}," file is the npm configuration file. It lists JavaScript dependencies and scripts used by the project.",[288,735,737],{"id":736},"package-lockjson",[57,738,739],{},"package-lock.json",[10,741,295,742,744],{},[57,743,739],{}," file, generated by npm, locks JavaScript dependencies to specific versions. Commit it to version control when using npm.",[26,746,748],{"id":747},"final-words","Final words",[10,750,751],{},"This first step gives us the foundation for the rest of the series. You now know where Laravel keeps its application code, configuration, database files, routes, and tests. As we add features, these folders will become familiar.",[10,753,754],{},"Next, we will make that foundation easier to maintain by configuring formatting, automatic refactoring, static analysis, and testing.",[756,757,758],"style",{},"html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":55,"searchDepth":119,"depth":119,"links":760},[761,762,789],{"id":28,"depth":119,"text":29},{"id":270,"depth":119,"text":271,"children":763},[764,765,766,767,768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788],{"id":290,"depth":125,"text":290},{"id":301,"depth":125,"text":301},{"id":325,"depth":125,"text":325},{"id":335,"depth":125,"text":335},{"id":352,"depth":125,"text":352},{"id":362,"depth":125,"text":362},{"id":376,"depth":125,"text":376},{"id":399,"depth":125,"text":399},{"id":417,"depth":125,"text":417},{"id":459,"depth":125,"text":459},{"id":472,"depth":125,"text":472},{"id":485,"depth":125,"text":486},{"id":492,"depth":125,"text":495},{"id":503,"depth":125,"text":506},{"id":514,"depth":125,"text":517},{"id":528,"depth":125,"text":531},{"id":539,"depth":125,"text":542},{"id":550,"depth":125,"text":553},{"id":561,"depth":125,"text":561},{"id":571,"depth":125,"text":574},{"id":692,"depth":125,"text":695},{"id":703,"depth":125,"text":706},{"id":714,"depth":125,"text":717},{"id":725,"depth":125,"text":728},{"id":736,"depth":125,"text":739},{"id":747,"depth":119,"text":748},"06469e25-715e-4a92-87b9-0db6db845a50","2025-02-25","A comprehensive guide to setting up your Laravel project and understanding its structure for a better development experience.","md",null,{},"\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsetting-up-your-laravel-project-structure-and-essentials","---\ncontentId: 06469e25-715e-4a92-87b9-0db6db845a50\npart: 1\ntitle: \"Setting Up Your Laravel Project Structure and Essentials\"\ndescription: \"A comprehensive guide to setting up your Laravel project and understanding its structure for a better development experience.\"\ndate: 2025-02-25\nseriesSlug: empower-and-dynamize-our-vitepress-blog-with-a-laravel-api\n---\n\nWelcome to the Laravel part of this series! 👋\n\nIn the previous series, we set up a VitePress blog in [Create a Blog with VitePress and Vue.js from Scratch](\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch). Now we are ready to build the Laravel API that will power its interactive features. You do not need to have read that series, but it provides useful context for what follows.\n\nIn this first article, we will create the Laravel project, explore its structure, and identify where the code we write throughout this series will live. By the end, you should feel comfortable finding your way around the application.\n\n## Setting up the project\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThis article does not cover installing Laravel itself. For that, refer to [the official documentation](https:\u002F\u002Flaravel.com\u002Fdocs\u002F12.x\u002Finstallation).\n::\n\nOne of Laravel's strengths is its CLI, which helps you create a new project quickly. Run the following command:\n\n```bash [terminal]\nlaravel new mimram --pest # Mimram is the name of the project\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nStarting with Laravel 12, the `laravel new` command no longer prompts for the testing framework. The `--pest` flag sets up Pest automatically.\n::\n\nThe setup should look like this:\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nFor this article, I'm using version 12.x of Laravel.\n::\n\n```txt [Example]\n   _                               _\n  | |                             | |\n  | |     __ _ _ __ __ ___   _____| |\n  | |    \u002F _` |  __\u002F _` \\ \\ \u002F \u002F _ \\ |\n  | |___| (_| | | | (_| |\\ V \u002F  __\u002F |\n  |______\\__,_|_|  \\__,_| \\_\u002F \\___|_|\n\n ┌ Which starter kit would you like to install? ────────────────┐\n │ › ● None                                                     │\n │   ○ React                                                    │\n │   ○ Vue                                                      │\n │   ○ Livewire                                                 │\n └──────────────────────────────────────────────────────────────┘\n```\n\nSince we have an existing frontend, select the `None` option.\n\nNext, it will ask about the database our application should use.\n\n```txt [Example]\n ┌ Which database will your application use? ───────────────────┐\n │ › ● SQLite                                                   │\n │   ○ MySQL                                                    │\n │   ○ MariaDB                                                  │\n │   ○ PostgreSQL                                               │\n │   ○ SQL Server (Missing PDO extension)                       │\n └──────────────────────────────────────────────────────────────┘\n```\n\nFor this project, choose SQLite.\n\nSQLite is a C library that stores data in a single database file on disk, making it portable and low-maintenance. It may not fit every use case, but it is an excellent choice for a simple blog that will not experience heavy traffic.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nTo learn more about SQLite, I recommend [High Performance SQLite](https:\u002F\u002Fhighperformancesqlite.com\u002F) by [Aaron Francis](https:\u002F\u002Fx.com\u002Faarondfrancis). It is an excellent series for mastering SQLite.\n::\n\nFinally, say yes when asked whether you want to install the JavaScript dependencies and build the assets.\n\nPerfect! We now have a fresh Laravel project in which to build our API.\n\n## Project structure\n\nHere's the project structure we will be working with:\n\n```text [Laravel Project Structure]\n├── app\n│   ├── Http\u002F\n│   ├── Models\u002F\n│   └── Providers\u002F\n├── bootstrap\n│   ├── app.php\n│   └── cache\u002F\n├── config\n│   ├── app.php\n│   ├── database.php\n│   └── mail.php\n├── database\n│   ├── migrations\u002F\n│   ├── factories\u002F\n│   └── seeders\u002F\n├── public\n│   ├── index.php\n│   ├── css\u002F\n│   └── js\u002F\n├── resources\n│   ├── views\u002F\n│   ├── css\u002F\n│   └── js\u002F\n├── routes\n│   ├── web.php\n│   └── api.php\n├── storage\n│   ├── app\u002F\n│   ├── framework\u002F\n│   └── logs\u002F\n├── tests\n│   ├── Feature\u002F\n│   └── Unit\u002F\n└── vendor\n```\n\nLet's dive into all the folders and files.\n\n### `app`\n\nThe `app` folder houses the core code of your application, including controllers, models, and services. It is the heart of the project and where you will spend most of your time coding.\n\n### `bootstrap`\n\nThe `bootstrap` folder contains files that initialize the application. It includes `app.php`, which creates and configures the application.\n\nThe folder also contains the `providers.php` file, which loads the service providers. A service provider registers services, routes, and Laravel extensions such as macros and helpers. Every Laravel package has a service provider as its entry point, and your application providers live in `app\u002FProviders`.\n\n### `config`\n\nThe `config` folder contains all the configuration files. Here, you can find settings for the database, mail, cache, and more.\n\n### `database`\n\nThe `database` folder stores database migrations, model factories, and seeders. Migrations version-control your database schema. Model factories generate test data conveniently, and seeders populate your database, often by using those factories.\n\nModel factories relate to models located in the `app\u002FModels` folder.\n\n### `node_modules`\n\nThe `node_modules` folder contains the JavaScript dependencies installed by npm, pnpm, or yarn. It is generated automatically and should not be committed to version control.\n\n### `public`\n\nThe `public` folder stores the front controller and public assets such as JavaScript, CSS, and images. It is the directory served by the web server. The `index.php` file is the application's entry point and routes incoming requests to Laravel.\n\n### `resources`\n\nThe `resources` folder contains view files and raw assets such as CSS and JavaScript. In Laravel, views are PHP files called Blade templates. Blade provides an elegant syntax for PHP code and directives such as `@if` and `@foreach`.\n\nRaw assets are compiled by Vite and stored in the `public\u002Fbuild` folder.\n\n### `routes`\n\nThe `routes` folder holds the application's routes. It includes web routes, API routes, and console routes. Each file manages a specific type of route: `web.php` handles browser-facing routes, while `api.php` handles API routes.\n\n### `storage`\n\nThe `storage` folder contains compiled Blade templates, file-based sessions, caches, logs, and other framework-generated files. It is divided into:\n\n1. `app`: Application-generated files.\n2. `framework`: Framework-generated files.\n3. `logs`: Application log files.\n\nLook for the `laravel.log` file in `storage\u002Flogs` for error logs and stack traces.\n\n### `tests`\n\nThe `tests` folder houses automated tests. Laravel includes Pest, a testing framework built on PHPUnit, for writing unit and feature tests. Testing ensures that your application behaves as expected and helps prevent regressions.\n\nThroughout this series, we will write tests for our application, showcasing Laravel's ease of use in test writing.\n\n### `vendor`\n\nThe `vendor` folder holds all PHP dependencies, automatically generated by Composer. It is akin to the `node_modules` folder for JavaScript but for PHP.\n\n### Root files\n\nHere's a list of files in the project root:\n\n### `.editorconfig`\n\nThe `.editorconfig` file helps maintain consistent coding styles for multiple developers across editors and IDEs. It defines styles like indentation, line endings, and character encoding.\n\n### `.env`\n\nThe `.env` file contains environment-specific configuration values, allowing you to configure the application without changing its code. It may include sensitive details such as database credentials and API keys.\n\n### `.env.example`\n\nThe `.env.example` file is a template for `.env`, providing the values needed to create a local configuration. Commit this file to version control so other developers know which variables are available.\n\n### `.gitattributes`\n\nThe `.gitattributes` file defines attributes for paths in your repository, controlling Git's handling of line endings, merge strategies, and other behaviors for specific files or directories.\n\n### `.gitignore`\n\nThe `.gitignore` file specifies files and directories Git should ignore, preventing sensitive data and unnecessary files from being committed.\n\n### `README.md`\n\nThe `README.md` file provides a project overview, covering setup, usage, and other essential details. It's often the first reference for new developers on the project.\n\n### `artisan`\n\nThe `artisan` file is Laravel's command-line interface. It provides commands for developing the application, running migrations, generating code, and executing tests.\n\n### `composer.json`\n\nThe `composer.json` file is Composer's configuration file. It lists PHP dependencies and project metadata such as the project name and description.\n\nThis file includes a `scripts` key for running `composer run` commands. For instance, `composer run test` executes application tests. Among these scripts, the `dev` script launches development necessities:\n\n```bash [composer.json]\nnpx concurrently -c \\\"#93c5fd,#c4b5fd,#fb7185,#fdba74\\\" \\\"php artisan serve\\\" \\\"php artisan queue:listen --tries=1\\\" \\\"php artisan pail --timeout=0\\\" \\\"npm run dev\\\" --names=server,queue,logs,vite\n```\n\nLaravel is more than a single process during development. The web server handles requests, the Vite server serves assets, and the queue and log processes handle their respective tasks.\n\nThe `composer run dev` command launches these processes in parallel using the `concurrently` npm package.\n\n### `composer.lock`\n\nThe `composer.lock` file, generated by Composer, locks dependencies to specific versions and makes installations reproducible. Commit this file to version control.\n\n### `phpunit.xml`\n\nThe `phpunit.xml` file configures PHPUnit, including its test suites, bootstrap file, and environment options.\n\n### `vite.config.js`\n\nThe `vite.config.js` file configures Vite, Laravel's frontend build tool, including the JavaScript and CSS entry points.\n\n### `package.json`\n\nThe `package.json` file is the npm configuration file. It lists JavaScript dependencies and scripts used by the project.\n\n### `package-lock.json`\n\nThe `package-lock.json` file, generated by npm, locks JavaScript dependencies to specific versions. Commit it to version control when using npm.\n\n## Final words\n\nThis first step gives us the foundation for the rest of the series. You now know where Laravel keeps its application code, configuration, database files, routes, and tests. As we add features, these folders will become familiar.\n\nNext, we will make that foundation easier to maintain by configuring formatting, automatic refactoring, static analysis, and testing.\n",{"title":5,"description":792},"empower-and-dynamize-our-vitepress-blog-with-a-laravel-api",{"loc":796},"series\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsetting-up-your-laravel-project-structure-and-essentials","G6ibOdbfN2oqDhw9U3TCN8lk5jbtt1paaHYwiqyIEeM",{"overview":804,"chapters":978},{"id":805,"title":806,"body":807,"contentId":963,"date":964,"description":965,"extension":793,"github":794,"meetTheInstructor":966,"meta":967,"navigation":152,"part":794,"path":968,"rawbody":969,"robots":794,"schemaOrg":794,"seo":970,"seriesSlug":799,"sitemap":971,"stem":972,"subtitle":973,"topics":974,"__hash__":977},"series\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api.md","Empower and Enhance Your VitePress Blog with a Laravel API",{"type":7,"value":808,"toc":960},[809,812,815,818,822,831,834,843,846,849,933,936,939,942,950,954],[10,810,811],{},"Hello! 👋",[10,813,814],{},"After building our VitePress blog, we are ready to make it more dynamic with a Laravel API.",[10,816,817],{},"In the previous series, we explored VitePress from the initial project setup to deployment on Cloudflare Pages. We built a functional, automated blog with SEO metadata, Open Graph images, and a GitHub projects page. The blog handled everything at build time, so publishing content was the only task left.",[819,820],"callout-read-more",{"id":821},"43c95b33-041c-4108-ab98-0d21ef60ed7f",[10,823,824,825,830],{},"This series introduces back-end development by creating a ",[17,826,829],{"href":827,"rel":828},"https:\u002F\u002Flaravel.com",[42],"Laravel"," API that gives our blog a few interactive features.",[10,832,833],{},"Until now, our blog has been mostly static. Content was generated at build time, with a small amount of data loaded dynamically, and the resulting HTML files were distributed through a CDN. By adding a Laravel API, we will let readers interact with the blog through features such as post reactions and comments.",[10,835,836,837,842],{},"Although the focus is on the back end, we will also integrate the API into our VitePress blog. We will use Vue.js and ",[17,838,841],{"href":839,"rel":840},"https:\u002F\u002Fpinia-colada.esm.dev\u002F",[42],"Pinia Colada"," as our data-fetching framework. VitePress is a Vue.js application, so we can extend it with the components we need.",[10,844,845],{},"The examples are designed to be easy to follow. Unnecessary complexity and over-engineering are neither desirable nor necessary here. We will focus on simplicity, clarity, and efficiency.",[10,847,848],{},"Throughout the series, we will build a Laravel API and integrate it with our VitePress blog. We will cover:",[850,851,852,859,888,899,905,915,921,927],"ul",{},[429,853,854,858],{},[855,856,857],"strong",{},"Setting up the Laravel project",": Create a new Laravel project and become familiar with its structure.",[429,860,861,864,865,870,871,870,876,881,882,887],{},[855,862,863],{},"Improving the development workflow",": Configure ",[17,866,869],{"href":867,"rel":868},"https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fpint",[42],"Pint",", ",[17,872,875],{"href":873,"rel":874},"https:\u002F\u002Fgithub.com\u002Frectorphp\u002Frector",[42],"Rector",[17,877,880],{"href":878,"rel":879},"https:\u002F\u002Fgithub.com\u002Flarastan\u002Flarastan",[42],"Larastan",", and ",[17,883,886],{"href":884,"rel":885},"https:\u002F\u002Fpestphp.com\u002F",[42],"Pest"," for formatting, refactoring, static analysis, and testing.",[429,889,890,893,894,44],{},[855,891,892],{},"Adding social authentication",": Let users sign in with GitHub through ",[17,895,898],{"href":896,"rel":897},"https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fsocialite",[42],"Laravel Socialite",[429,900,901,904],{},[855,902,903],{},"Connecting the applications",": Configure Sanctum, CORS, CSRF protection, and the first requests between the VitePress frontend and the Laravel API.",[429,906,907,910,911,914],{},[855,908,909],{},"Managing authentication state",": Use ",[17,912,841],{"href":839,"rel":913},[42]," to retrieve the current user and log out with an optimistic update.",[429,916,917,920],{},[855,918,919],{},"Building the comment API",": Create the models, relationships, endpoints, validation, authorization, and tests for comments.",[429,922,923,926],{},[855,924,925],{},"Keeping the backend in sync",": Generate post metadata from VitePress and synchronize it with the Laravel database.",[429,928,929,932],{},[855,930,931],{},"Building the comment interface",": Fetch, create, edit, and delete comments from the VitePress frontend.",[10,934,935],{},"By the end of the series, you will have a blog backed by a Laravel API. Readers will be able to sign in with GitHub and leave comments, and the architecture will be ready for additional interactive features.",[10,937,938],{},"Testing is part of the development process and will be included at each stage, so it does not need a dedicated article.",[10,940,941],{},"If you have questions, feedback, or suggestions, feel free to share them in the comments. Your input helps improve the series.",[31,943,944],{"color":33,"icon":34},[10,945,946,947,949],{},"This series assumes prior knowledge of TypeScript, Vue.js, and Laravel. If you are unfamiliar with any of these technologies, review the ",[17,948,20],{"href":19}," first.",[26,951,953],{"id":952},"chapters","Chapters",[955,956],"series-chapters-list",{"className":957},[958,959],"mx-auto","max-w-5xl",{"title":55,"searchDepth":119,"depth":119,"links":961},[962],{"id":952,"depth":119,"text":953},"676d45dd-eb18-42ec-803e-b9d6b7f04b42","2024-11-19","Transform your VitePress blog into a dynamic platform with a Laravel API. Leverage backend API capabilities to create advanced features.","I create this series because I love \u003Cstrong>VitePress\u003C\u002Fstrong> and \u003Cstrong>Laravel\u003C\u002Fstrong>. I truly believe that combining the two results in a simple yet \u003Cstrong>powerful solution\u003C\u002Fstrong> for creating a blog. I want to empower developers to enhance their VitePress blogs with a Laravel API to create advanced features.",{},"\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api","---\ncontentId: 676d45dd-eb18-42ec-803e-b9d6b7f04b42\ntitle: Empower and Enhance Your VitePress Blog with a Laravel API\nsubtitle: Transform your VitePress blog into a dynamic platform with an API\ndescription: Transform your VitePress blog into a dynamic platform with a Laravel API. Leverage backend API capabilities to create advanced features.\ndate: 2024-11-19\ntopics:\n  - laravel\n  - vitepress\n  - api\nmeetTheInstructor: I create this series because I love \u003Cstrong>VitePress\u003C\u002Fstrong> and \u003Cstrong>Laravel\u003C\u002Fstrong>. I truly believe that combining the two results in a simple yet \u003Cstrong>powerful solution\u003C\u002Fstrong> for creating a blog. I want to empower developers to enhance their VitePress blogs with a Laravel API to create advanced features.\nseriesSlug: empower-and-dynamize-our-vitepress-blog-with-a-laravel-api\n---\n\nHello! 👋\n\nAfter building our VitePress blog, we are ready to make it more dynamic with a Laravel API.\n\nIn the previous series, we explored VitePress from the initial project setup to deployment on Cloudflare Pages. We built a functional, automated blog with SEO metadata, Open Graph images, and a GitHub projects page. The blog handled everything at build time, so publishing content was the only task left.\n\n\u003CCalloutReadMore id=\"43c95b33-041c-4108-ab98-0d21ef60ed7f\" \u002F>\n\nThis series introduces back-end development by creating a [Laravel](https:\u002F\u002Flaravel.com) API that gives our blog a few interactive features.\n\nUntil now, our blog has been mostly static. Content was generated at build time, with a small amount of data loaded dynamically, and the resulting HTML files were distributed through a CDN. By adding a Laravel API, we will let readers interact with the blog through features such as post reactions and comments.\n\nAlthough the focus is on the back end, we will also integrate the API into our VitePress blog. We will use Vue.js and [Pinia Colada](https:\u002F\u002Fpinia-colada.esm.dev\u002F) as our data-fetching framework. VitePress is a Vue.js application, so we can extend it with the components we need.\n\nThe examples are designed to be easy to follow. Unnecessary complexity and over-engineering are neither desirable nor necessary here. We will focus on simplicity, clarity, and efficiency.\n\nThroughout the series, we will build a Laravel API and integrate it with our VitePress blog. We will cover:\n\n- **Setting up the Laravel project**: Create a new Laravel project and become familiar with its structure.\n- **Improving the development workflow**: Configure [Pint](https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fpint), [Rector](https:\u002F\u002Fgithub.com\u002Frectorphp\u002Frector), [Larastan](https:\u002F\u002Fgithub.com\u002Flarastan\u002Flarastan), and [Pest](https:\u002F\u002Fpestphp.com\u002F) for formatting, refactoring, static analysis, and testing.\n- **Adding social authentication**: Let users sign in with GitHub through [Laravel Socialite](https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fsocialite).\n- **Connecting the applications**: Configure Sanctum, CORS, CSRF protection, and the first requests between the VitePress frontend and the Laravel API.\n- **Managing authentication state**: Use [Pinia Colada](https:\u002F\u002Fpinia-colada.esm.dev\u002F) to retrieve the current user and log out with an optimistic update.\n- **Building the comment API**: Create the models, relationships, endpoints, validation, authorization, and tests for comments.\n- **Keeping the backend in sync**: Generate post metadata from VitePress and synchronize it with the Laravel database.\n- **Building the comment interface**: Fetch, create, edit, and delete comments from the VitePress frontend.\n\nBy the end of the series, you will have a blog backed by a Laravel API. Readers will be able to sign in with GitHub and leave comments, and the architecture will be ready for additional interactive features.\n\nTesting is part of the development process and will be included at each stage, so it does not need a dedicated article.\n\nIf you have questions, feedback, or suggestions, feel free to share them in the comments. Your input helps improve the series.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThis series assumes prior knowledge of TypeScript, Vue.js, and Laravel. If you are unfamiliar with any of these technologies, review the [Create a Blog with VitePress and Vue.js from Scratch](\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch) first.\n::\n\n## Chapters\n\n::series-chapters-list\n---\nclass: mx-auto max-w-5xl\n---\n::\n",{"title":806,"description":965},{"loc":968},"series\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api","Transform your VitePress blog into a dynamic platform with an API",[67,975,976],"vitepress","api","JLBtX9BKfN72BkhcYisEXraNGTvZSnT5YHM05A_uemk",[979,980,985,990,995,1000,1005,1010],{"contentId":790,"title":5,"description":792,"path":796,"part":63,"github":794,"topics":794},{"contentId":981,"title":982,"description":983,"path":984,"part":119,"github":794,"topics":794},"d566d5f4-3c4a-44e5-89cb-b3c547673ffa","Pint, Rector, Larastan, and Pest: Essentials for Success","Explore the four indispensable tools for maintaining code quality and consistency in Laravel projects: Pint, Rector, Larastan, and Pest.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fpint-larastan-rector-and-pest-essential-for-success",{"contentId":986,"title":987,"description":988,"path":989,"part":125,"github":794,"topics":794},"3729f419-a8b6-486c-a845-ab5ba1a33172","Effortless Social Authentication with Laravel Socialite","Add GitHub authentication to Laravel with Socialite, OAuth callbacks, database synchronization, secure sessions, and test-first development.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Feffortless-social-authentication-with-laravel-socialite",{"contentId":991,"title":992,"description":993,"path":994,"part":131,"github":794,"topics":794},"b07ec3b5-ca56-4d14-ae2f-8c0702218293","Building a Simple Comment System for User Engagement","Build a Laravel comment API with models, migrations, resources, policies, form requests, controllers, routes, and comprehensive tests.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fbuilding-a-simple-comment-system-for-user-engagement",{"contentId":996,"title":997,"description":998,"path":999,"part":137,"github":794,"topics":794},"53a607df-d10e-4423-966c-500d2885e6e0","Automating Your Backend to Stay in Sync Effortlessly","Generate frontend metadata with VitePress, synchronize posts with Laravel, and keep the backend database aligned automatically.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fautomating-your-backend-to-stay-in-sync-effortlessly",{"contentId":1001,"title":1002,"description":1003,"path":1004,"part":143,"github":794,"topics":794},"e6040e0a-4997-40d6-bde8-332cbca0f307","Bridging the Gap: Connecting Your Frontend and Backend","Connect a VitePress frontend to a Laravel API with Sanctum, CORS, CSRF protection, shared credentials, and a reusable API client.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fbridging-the-gap-connecting-your-frontend-and-backend",{"contentId":1006,"title":1007,"description":1008,"path":1009,"part":149,"github":794,"topics":794},"d507f8af-7c76-4660-859e-23af11c0728e","Streamlining User Authentication from Frontend to Backend","Connect frontend authentication to Laravel with a current-user query, GitHub logout flow, Pinia Colada caching, and optimistic state updates.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fstreamlining-user-authentication-from-frontend-to-backend",{"contentId":1011,"title":1012,"description":1013,"path":1014,"part":156,"github":794,"topics":794},"1b2a6cc0-c10f-421a-9344-60cb1583a136","Simplifying Comment Querying and Editing with Pinia Colada","Build the VitePress comment interface with Pinia Colada queries, mutations, optimistic updates, reusable Vue components, and permissions.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsimplifying-comment-querying-and-editing-with-pinia-colada",1795016693312]