laravel-best-practices
Laravel development best practices covering service providers, dependency injection, facades, and the Laravel Way.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Laravel development best practices covering service providers, dependency injection, facades, and the Laravel Way.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
PHP Artisan CLI patterns including make commands, flags, custom commands, and AI-friendly usage.
Advanced Eloquent ORM patterns including relationships, eager loading, factories, and query optimization.
Laravel Tinker best practices for debugging, testing ideas, and data exploration. When and how to use safely.
Laravel-native error handling patterns. Renderable exceptions, Livewire traits strategies, and user-facing notifications.
Integrate Anthropic Claude API with Laravel. HTTP client, message format, error handling. Use when calling Claude models from Laravel applications.
API security patterns for Laravel. Rate limiting, headers, CORS, Sanctum tokens, input validation. Use when building or securing API endpoints.
| name | laravel-best-practices |
| description | Laravel development best practices covering service providers, dependency injection, facades, and the Laravel Way. |
Laravel has conventions that make development faster and code more maintainable. Follow these principles.
// Register bindings in boot() or register()
public function register(): void
{
$this->app->bind(PaymentGateway::class, StripeGateway::class);
}
public function boot(): void
{
// Event listeners, view composers, etc.
}
public function __construct(
private PaymentService $payments,
private MailService $mail,
) {}
public function store(StorePostRequest $request, PostService $service): RedirectResponse
{
$service->create($request->validated());
return redirect()->route('posts.index');
}
| Use Facade | Use Injection |
|---|---|
| Quick prototyping | Production code |
| View/Blade files | Controllers/Services |
| Simple operations | Complex dependencies |
env() ONLY in config filesconfig() everywhere elsephp artisan config:cache// ✅ Correct
config('app.name');
// ❌ Wrong
env('APP_NAME');
$fillable or $guarded definedclass Post extends Model
{
protected $fillable = ['title', 'body', 'user_id'];
protected $casts = [
'published_at' => 'datetime',
'metadata' => 'array',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function scopePublished(Builder $query): void
{
$query->whereNotNull('published_at');
}
}
class PostController extends Controller
{
public function store(StorePostRequest $request, PostService $service): RedirectResponse
{
$service->createPost($request->validated());
return redirect()->route('posts.index');
}
}
class StorePostRequest extends FormRequest
{
public function authorize(): bool
{
return true; // Or policy check
}
public function rules(): array
{
return [
'title' => ['required', 'string', 'max:255'],
'body' => ['required', 'string'],
];
}
}
Use php artisan make:* for everything:
make:model Post -mfsc (full stack)make:controller PostController --resourcemake:request StorePostRequestmake:test CreatePostTest --pestmake:livewire Posts/CreatePostmake:filament-resource Post --generate# ✅ Non-interactive (AI-friendly)
php artisan make:model Post -mfsc --no-interaction
# ❌ May prompt for input
php artisan make:model Post
bootstrap/
├── app.php # Middleware, exceptions, routing
├── providers.php # Service providers
routes/
├── console.php # Console commands & schedule
app/
├── Console/Commands/ # Auto-discovered, no registration needed
app/
├── Http/Kernel.php # Middleware registration
├── Console/Kernel.php # Schedule & commands
├── Exceptions/Handler.php
├── Providers/
// Check for legacy structure
if (file_exists(base_path('app/Http/Kernel.php'))) {
// Laravel 10 structure - use Kernel.php
} else {
// Laravel 11+ structure - use bootstrap/app.php
}