
API Resources & Authentication
API routes, resource controllers, API resources, pagination, rate limiting, CORS, Sanctum (SPA/tokens), Passport/OAuth2, scopes
1In Laravel, where to define API routes by default?
In Laravel, where to define API routes by default?
Antwoord
API routes are defined in the routes/api.php file. These routes are automatically prefixed with /api and have the api middleware applied by default. Unlike web routes defined in routes/web.php, API routes don't use sessions and are designed for stateless calls (REST, GraphQL, etc.).
2Which Artisan command generates a resource controller for an API?
Which Artisan command generates a resource controller for an API?
Antwoord
The php artisan make:controller PostController --api command generates a resource controller optimized for APIs. This controller contains the index, store, show, update and destroy methods, but WITHOUT the create and edit methods (which serve to display forms in web context, useless for a REST API). This --api option avoids superfluous code in an API-only context.
3What is an API Resource in Laravel?
What is an API Resource in Laravel?
Antwoord
An API Resource is a transformation class that converts an Eloquent model into a JSON array for API responses. It allows precise control over which attributes are exposed, adding computed fields, hiding sensitive data (passwords), and managing relationships. This decouples the database structure from the API response and ensures consistency in output formats.
How to create an API Resource for a User model?
How to return a paginated collection with an API Resource?
+23 gespreksvragen
Andere Laravel-sollicitatieonderwerpen
PHP Basics
PHP OOP Essentials
Composer & Autoloading
Laravel Fundamentals
Laravel Routing
Blade Templates
Request & Response
Eloquent ORM Basics
Eloquent Relationships
Migrations & Schema Builder
Validation & Forms
Authentication
Authorization & Policies
Middleware
Service Container & DI
Queues & Jobs
Events & Listeners
Notifications & Mail
File Storage
Testing & PHPUnit
Caching
Livewire & Inertia
Eloquent Advanced
Repository Pattern
Laravel Packages
Performance Optimization
Security Best Practices
Laravel Octane
Laravel Distributed Systems
Observability & Monitoring
Deployment & DevOps
Beheers Laravel voor je volgende gesprek
Krijg toegang tot alle vragen, flashcards, technische tests, code review-oefeningen en gespreksimulatoren.
Begin gratis