📜  laravel create - PHP (1)

📅  最后修改于: 2023-12-03 14:43:44.854000             🧑  作者: Mango

Laravel Create - PHP

Laravel is a web application framework written in PHP programming language. Laravel provides an expressive, elegant syntax and a variety of helpful tools to make building web applications easier and faster.

One of the most common tasks in Laravel is creating a new project. This can be done using the create-project command provided by Composer, a popular package manager for PHP.

Installing Laravel

To get started with Laravel, you need to have PHP and Composer installed on your system. You can check if you have them installed by running the following commands:

php --version
composer --version

If they are not installed, you can download and install them from the following links:

Once you have PHP and Composer installed, you can create a new Laravel project using the following command:

composer create-project --prefer-dist laravel/laravel my-project

Replace my-project with the name you want to give to your project.

This command will download the latest version of Laravel and its dependencies and create a new project with the provided name. The --prefer-dist option tells Composer to prefer downloading pre-built packages instead of building them from source, which can save time and disk space.

Understanding the Project Structure

When you create a new Laravel project, you will see a directory structure like this:

my-project/
|-- app/
|-- bootstrap/
|-- config/
|-- database/
|-- public/
|-- resources/
|-- routes/
|-- storage/
|-- tests/
|-- vendor/
|-- .env
|-- .env.example
|-- .gitignore
|-- composer.json
|-- composer.lock
|-- package.json
|-- README.md

Let's go through each directory and understand what it contains:

  • app/: This directory contains the core code of your application, including controllers, models, views, and other classes.
  • bootstrap/: This directory contains the files that bootstrap the framework and the application.
  • config/: This directory contains the configuration files for your application, including database configuration, cache configuration, and session configuration.
  • database/: This directory contains the database migrations and seeds for your application.
  • public/: This directory contains the front controller of your application (index.php) and the assets (images, CSS, JavaScript, etc.) used by your application.
  • resources/: This directory contains the views, language files, and assets (less, sass, coffee, etc.) used by your application.
  • routes/: This directory contains the route definitions for your application.
  • storage/: This directory contains the compiled views, cache, and other files generated by your application.
  • tests/: This directory contains the automated tests for your application.
  • vendor/: This directory contains the Composer dependencies for your application.
  • .env: This file contains the environment variables for your application.
  • .env.example: This file is an example of the .env file and contains the default values for the environment variables.
  • .gitignore: This file tells Git which files to ignore when committing changes to your application.
  • composer.json: This file contains the dependencies and configuration for Composer.
  • composer.lock: This file contains the exact version of each dependency installed by Composer.
  • package.json: This file contains the dependencies and configuration for npm.
  • README.md: This file contains the documentation for your application.
Conclusion

Creating a new Laravel project is easy and fast using Composer. Once you have created your project, you can start building your application by writing controllers, models, views, and routes. Laravel provides many features and tools to help you build web applications quickly and efficiently, so don't hesitate to try it out!