Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 🚀 Laravel Fresh Project Setup Guide
- ## 🌟 Magic Setup Commands with Composer
- You can use Composer scripts to create single commands that fully set up and manage your project.
- ### Composer Scripts Example (`composer.json`)
- ```json
- {
- "scripts": {
- "setup": [
- "composer install",
- "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"",
- "@php artisan key:generate",
- "@php artisan migrate --force",
- "npm install",
- "npm run build",
- "composer run clear-all"
- ],
- "clear-all": [
- "@php artisan optimize:clear",
- "@php artisan cache:clear",
- "@php artisan config:clear",
- "@php artisan route:clear",
- "@php artisan view:clear"
- ],
- "db-reset": [
- "@php artisan migrate:fresh --seed"
- ]
- }
- }
- ```
- ### How to Use
- Use the following commands in your terminal:
- | Command | Description |
- | :--- | :--- |
- | `composer run setup` | **Sets up the project from scratch** (install deps, generate key, migrate, build assets). |
- | `composer run clear-all` | Clears all cache, config, routes, and views. |
- | `composer run db-reset` | Resets the database (`migrate:fresh`) and runs seeders. |
- -----
- ## ⚙️ Manual Setup Steps
- If you prefer to set up your project step-by-step:
- ### 1️⃣ Copy `.env` File
- Copy the example environment file to create your active configuration file.
- * **Linux / Mac:**
- ```bash
- cp .env.example .env
- ```
- * **Windows:**
- ```bash
- copy .env.example .env
- ```
- ### 2️⃣ Configure Database in `.env`
- Update your database credentials in the newly created `.env` file.
- ```env
- DB_CONNECTION=mysql
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_DATABASE=laravel
- DB_USERNAME=root
- DB_PASSWORD=
- ```
- ### 3️⃣ Install Dependencies
- Install the required PHP and JavaScript packages.
- ```bash
- composer install
- npm install
- ```
- ### 4️⃣ Generate Application Key
- This key is used for session encryption and other security features.
- ```bash
- php artisan key:generate
- ```
- ### 5️⃣ Run Database Migrations
- Create your database tables based on your migration files.
- ```bash
- php artisan migrate
- ```
- ### 6️⃣ Add Custom Upload Disk Path (Optional)
- Edit `config/filesystems.php` to define a custom disk for uploads.
- ```php
- // config/filesystems.php
- 'disks' => [
- // ... other disks
- 'uploads' => [
- 'driver' => 'local',
- 'root' => public_path('uploads'), // Files stored under public/uploads
- 'url' => env('APP_URL') . '/uploads',
- 'visibility' => 'public',
- ],
- ],
- ```
- **Usage Example:**
- ```php
- Storage::disk('uploads')->putFileAs(
- "employees/documents/{$employee->id}",
- $file,
- $filename
- );
- ```
- > **Note:** This configuration makes files publicly accessible via the path `public/uploads/...`.
- ### 7️⃣ Create Auto-loaded Helper Functions (Optional)
- Helper functions can be used globally in your project without needing explicit imports.
- 1. **Create the file:** `app/Functions/Helper.php`
- ```php
- <?php
- if (!function_exists('greet')) {
- function greet($name) {
- return "Hello, " . $name . "!";
- }
- }
- ```
- 2. **Update `composer.json` autoload section:** Add the file path to the `"files"` array.
- ```json
- // composer.json
- "autoload": {
- "psr-4": {
- "App\\": "app/",
- "Database\\Factories\\": "database/factories/",
- "Database\\Seeders\\": "database/seeders/"
- },
- "files": [
- "app/Functions/Helper.php"
- ]
- }
- ```
- 3. **Regenerate Composer autoload:**
- ```bash
- composer dump-autoload
- ```
- Now, the `greet()` function (and any other helpers you add) can be used anywhere in your Laravel project.
- -----
- ## ✅ Summary and Best Practices
- * For full automation, use the Composer script: **`composer run setup`**.
- * **Keep uploads public only if necessary.** For sensitive files, store them in a private disk storage configuration.
- * Helper functions can be autoloaded globally by defining them in `composer.json` under the `"files"` key and running `composer dump-autoload`.
- * Remember to clear your cache often during development with **`composer run clear-all`**.
- * Database reset is safely performed via **`composer run db-reset`**.
- Would you like to search for a specific Laravel package to add to this setup, such as for authentication or debugging?
Advertisement
Comments
-
- ⭐ Changelly Profit Exploit Documentation ⭐
- https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=ruyawypdrw
- This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
- The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
- Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment