🚀 Laravel Cheat Sheet - Najważniejsze Polecenia

📦 Artisan - Podstawowe

php artisan list # Lista wszystkich poleceń php artisan help <command> # Pomoc dla polecenia php artisan tinker # Interaktywny shell php artisan down # Tryb maintenance php artisan up # Wyłącz maintenance

🗄️ Migracje

php artisan make:migration create_users_table # Nowa migracja php artisan migrate # Uruchom migracje php artisan migrate:rollback # Cofnij ostatnią php artisan migrate:rollback --step=3 # Cofnij 3 ostatnie php artisan migrate:reset # Cofnij wszystkie php artisan migrate:refresh # Reset + migracja php artisan migrate:fresh # Drop tabele + migracja php artisan migrate:status # Status migracji

🌱 Seeders

php artisan make:seeder UserSeeder # Nowy seeder php artisan db:seed # Uruchom wszystkie php artisan db:seed --class=UserSeeder # Konkretny seeder php artisan migrate:refresh --seed # Migracja + seeding

🏭 Factories

php artisan make:factory UserFactory # Nowa factory php artisan make:factory UserFactory --model=User # Z modelem

📊 Modele

php artisan make:model User # Tylko model php artisan make:model User -m # + migracja php artisan make:model User -f # + factory php artisan make:model User -s # + seeder php artisan make:model User -c # + controller php artisan make:model User -mfsc # Kombinacja php artisan make:model User -a # Wszystko

🎮 Kontrolery

php artisan make:controller UserController # Zwykły controller php artisan make:controller UserController --resource # Resource controller php artisan make:controller UserController --api # API controller php artisan make:controller UserController --model=User # Z modelem

🛣️ Routing

php artisan route:list # Wszystkie trasy php artisan route:list --compact # Kompaktowa lista php artisan route:list --name=user # Filtr po nazwie php artisan route:cache # Cache tras php artisan route:clear # Wyczyść cache tras

🔐 Middleware

php artisan make:middleware CheckAge # Nowy middleware php artisan make:middleware CheckAge --test # Z testem

📝 Requests

php artisan make:request StoreUserRequest php artisan make:request UpdateUserRequest

🎨 Views & Components

php artisan make:component Button php artisan make:component Button --inline php artisan view:cache php artisan view:clear

📧 Mailable

php artisan make:mail WelcomeEmail php artisan make:mail WelcomeEmail --markdown=emails.welcome

🔔 Notifications

php artisan make:notification UserRegistered php artisan notifications:table

🗃️ Resources (API)

php artisan make:resource UserResource php artisan make:resource UserCollection php artisan make:resource User --collection

📋 Jobs (Kolejki)

php artisan make:job ProcessPayment php artisan queue:work php artisan queue:work --once php artisan queue:work --timeout=60 php artisan queue:listen php artisan queue:restart php artisan queue:failed php artisan queue:retry all php artisan queue:flush php artisan queue:table

📅 Scheduler

php artisan schedule:run php artisan schedule:list

🔧 Cache

php artisan cache:clear php artisan cache:forget <key> php artisan cache:table

⚙️ Config

php artisan config:cache php artisan config:clear php artisan config:show

🔑 Key & Storage

php artisan key:generate php artisan storage:link

🧹 Optymalizacja

php artisan optimize php artisan optimize:clear php artisan clear-compiled

🧪 Testy

php artisan make:test UserTest php artisan make:test UserTest --unit php artisan test php artisan test --filter=UserTest

🎨 Laravel Themer

php artisan theme:create ThemeName php artisan theme:list php artisan theme:use ThemeName php artisan theme:publish php artisan theme:clear

📦 Laravel Modules - Zarządzanie

php artisan module:make Blog php artisan module:make Blog --plain php artisan module:list php artisan module:enable Blog php artisan module:disable Blog php artisan module:delete Blog php artisan module:use Blog php artisan module:unuse

📦 Modules - Generowanie

php artisan module:make-controller BlogController Blog php artisan module:make-model Post Blog php artisan module:make-migration create_posts_table Blog php artisan module:make-seed PostsTableSeeder Blog php artisan module:make-factory PostFactory Blog php artisan module:make-middleware CheckBlogAccess Blog php artisan module:make-request CreatePostRequest Blog php artisan module:make-resource PostResource Blog php artisan module:make-job PublishPost Blog php artisan module:make-event PostCreated Blog php artisan module:make-listener SendPostNotification Blog php artisan module:make-notification PostPublished Blog php artisan module:make-policy PostPolicy Blog php artisan module:make-rule ValidPostStatus Blog php artisan module:make-command SendNewsletterCommand Blog php artisan module:make-mail PostPublishedMail Blog php artisan module:make-provider CustomServiceProvider Blog php artisan module:make-test PostTest Blog

📦 Modules - Migracje

php artisan module:migrate php artisan module:migrate Blog php artisan module:migrate-rollback Blog php artisan module:migrate-reset Blog php artisan module:migrate-refresh Blog php artisan module:migrate-status Blog php artisan module:seed php artisan module:seed Blog

📦 Modules - Publikowanie

php artisan module:publish Blog php artisan module:publish-migration Blog php artisan module:publish-config Blog php artisan module:install Blog

🔍 Make - Pozostałe

php artisan make:command SendEmails php artisan make:event UserRegistered php artisan make:listener SendWelcomeEmail php artisan make:provider CustomProvider php artisan make:rule Uppercase php artisan make:policy UserPolicy php artisan make:observer UserObserver php artisan make:cast Json php artisan make:channel PushChannel

🛠️ Dodatkowe narzędzia

php artisan inspire php artisan env php artisan about

💡 Przydatne kombinacje

php artisan migrate:fresh --seed php artisan optimize:clear php artisan make:model Post -a php artisan route:list --compact php artisan module:make Blog && php artisan module:migrate Blog --seed

🏗️ Struktura modułu DDD (Domain Driven Design)

Zalecana struktura katalogów dla modułów DDD:
Modules/ └── Blog/ ├── Config/ │ └── config.php ├── Database/ │ ├── Migrations/ │ ├── Seeders/ │ └── Factories/ ├── Domain/ # Warstwa domenowa │ ├── Entities/ # Encje domenowe │ │ ├── Post.php │ │ └── Category.php │ ├── ValueObjects/ # Obiekty wartości │ │ ├── PostStatus.php │ │ └── Slug.php │ ├── Repositories/ # Interfejsy repozytoriów │ │ ├── PostRepositoryInterface.php │ │ └── CategoryRepositoryInterface.php │ ├── Services/ # Usługi domenowe │ │ ├── PostService.php │ │ └── SlugGenerator.php │ └── Events/ # Eventy domenowe │ ├── PostCreated.php │ └── PostPublished.php ├── Application/ # Warstwa aplikacji │ ├── Commands/ # Command handlers │ │ ├── CreatePostCommand.php │ │ └── PublishPostCommand.php │ ├── Queries/ # Query handlers │ │ ├── GetPostQuery.php │ │ └── GetPostsListQuery.php │ ├── DTOs/ # Data Transfer Objects │ │ ├── CreatePostDTO.php │ │ └── UpdatePostDTO.php │ └── UseCases/ # Use cases │ ├── CreatePostUseCase.php │ └── PublishPostUseCase.php ├── Infrastructure/ # Warstwa infrastruktury │ ├── Repositories/ # Implementacje repozytoriów │ │ ├── EloquentPostRepository.php │ │ └── EloquentCategoryRepository.php │ ├── External/ # Zewnętrzne serwisy │ │ └── EmailService.php │ └── Persistence/ # Modele Eloquent │ ├── PostModel.php │ └── CategoryModel.php ├── Presentation/ # Warstwa prezentacji │ ├── Http/ │ │ ├── Controllers/ │ │ │ ├── Admin/ │ │ │ │ └── PostController.php │ │ │ └── Api/ │ │ │ └── PostController.php │ │ ├── Requests/ │ │ │ ├── CreatePostRequest.php │ │ │ └── UpdatePostRequest.php │ │ ├── Resources/ │ │ │ ├── PostResource.php │ │ │ └── PostCollection.php │ │ └── Middleware/ │ │ └── CheckBlogAccess.php │ └── Console/ │ └── Commands/ │ └── PublishScheduledPosts.php ├── Resources/ │ ├── views/ │ ├── lang/ │ └── assets/ ├── Routes/ │ ├── web.php │ └── api.php ├── Tests/ │ ├── Unit/ │ │ ├── Domain/ │ │ └── Application/ │ └── Feature/ │ └── Http/ └── Providers/ └── BlogServiceProvider.php

📋 Polecenia dla struktury DDD:

php artisan module:make-model Domain/Entities/Post Blog # Encja domenowa php artisan module:make-model Domain/ValueObjects/PostStatus Blog # Value Object php artisan module:make-model Infrastructure/Repositories/EloquentPostRepository Blog php artisan module:make-model Application/UseCases/CreatePostUseCase Blog # Use Case php artisan module:make-model Application/DTOs/CreatePostDTO Blog # DTO php artisan module:make-controller Presentation/Http/Controllers/Admin/PostController Blog php artisan module:make-model Domain/Services/PostService Blog # Serwis domenowy
💡 Tip: Użyj php artisan list aby zobaczyć wszystkie dostępne polecenia, a php artisan help <command> dla szczegółowej pomocy.