📋 Шпаргалки по веб-разработке
Готовый синтаксис под рукой: 10 шпаргалок по
PHP 8, JavaScript (ES2024), TypeScript, CSS, SQL (PostgreSQL/MySQL), Git, Linux / Bash, Docker, React, Laravel.
🔺 Laravel
ARTISAN
| Сервер / консоль | php artisan serve php artisan tinker |
|---|
| Генерация | php artisan make:model Product -mcr |
|---|
| Ещё | make:request make:middleware make:job make:test |
|---|
| Миграции | migrate migrate:rollback migrate:fresh --seed |
|---|
| Маршруты / кеш | route:list config:cache route:cache |
|---|
| Очереди | queue:work queue:restart queue:failed |
МАРШРУТЫ
| Базовый | Route::get("/products", [ProductController::class, "index"]) |
|---|
| CRUD | Route::apiResource("products", ProductController::class) |
|---|
| Группа | Route::middleware("auth:sanctum")->prefix("admin")->group(...) |
|---|
| Параметр | Route::get("/p/{product}", ...) // Route Model Binding |
|---|
| Имя | ->name("products.index") route("products.index") |
ELOQUENT
| Поиск | Product::find($id) findOrFail($id) where(...)->first() |
|---|
| Список | Product::where("active", true)->latest()->paginate(20) |
|---|
| Создать / обновить | Product::create($data) $p->update($data) |
|---|
| Связи | hasMany(Order::class) belongsTo(User::class) belongsToMany(Tag::class) |
|---|
| Жадная загрузка | Order::with(["items.product", "user"])->get() // лечит N+1 |
|---|
| Счётчики | ->withCount("reviews") |
|---|
| Условно | ->when($request->status, fn($q, $s) => $q->where("status", $s)) |
|---|
| Скоуп | public function scopePublished($q) { $q->whereNotNull("published_at"); } |
ВАЛИДАЦИЯ И ОТВЕТЫ
| FormRequest | public function rules(): array { return ["title" => ["required","max:255"]]; } |
|---|
| Инлайн | $data = $request->validate([...]); |
|---|
| Частые правила | required nullable email exists:table,id unique:users min max in:a,b |
|---|
| Ресурс | return ProductResource::collection($products); |
|---|
| JSON / статус | return response()->json($data, 201); |
|---|
| Аборт | abort(404); abort_if($cond, 403); |
ОЧЕРЕДИ, СОБЫТИЯ, ПЛАНИРОВЩИК
| Задача в очередь | SendMail::dispatch($order); |
|---|
| Ретраи | public int $tries = 3; public array $backoff = [10, 60]; |
|---|
| Событие | OrderPaid::dispatch($order); |
|---|
| Слушатель | class SendReceipt implements ShouldQueue { public function handle(OrderPaid $e) {} } |
|---|
| Расписание | Schedule::command("reports:daily")->dailyAt("03:00"); |
ПРОЧЕЕ
| Auth | $request->user() auth()->id() Auth::check() |
|---|
| Токен API | $user->createToken("app")->plainTextToken |
|---|
| Транзакция | DB::transaction(fn() => ...) |
|---|
| Кеш | Cache::remember("key", 300, fn() => heavy()) |
|---|
| Storage | Storage::disk("s3")->put($path, $content) |
|---|
| Логи / отладка | Log::info($msg) dd($var) ray($var) |
|---|
| Тест | $this->actingAs($user)->postJson("/api/orders", $data)->assertCreated(); |