# PHP Laravel Framework Sollicitatievragen 2026: Eloquent, Queues en Architectuurpatronen > Bereid je voor op Laravel-sollicitaties 2026: Eloquent ORM, queue-systemen, Service Container en moderne architectuurpatronen met praktische codevoorbeelden. - Published: 2026-09-16 - Updated: 2026-09-16 - Author: Anthony Fillion-Maillet - Reading time: 5 min --- Het Laravel-framework blijft in 2026 een van de meest gebruikte PHP-frameworks voor enterprise-applicaties. Ontwikkelaars die zich voorbereiden op technische sollicitatiegesprekken moeten een diepgaand begrip tonen van Eloquent ORM, queue-systemen en moderne architectuurpatronen. > Deze gids behandelt geavanceerde Laravel-concepten die vaak worden gevraagd in sollicitatiegesprekken voor senior ontwikkelaars. Elke vraag bevat praktische codevoorbeelden en legt de onderliggende principes uit. ## Eloquent ORM: Geavanceerde Concepten ### Wat is het verschil tussen eager loading en lazy loading in Eloquent? Eager loading lost het N+1-probleem op door gerelateerde modellen in een enkele query te laden. Lazy loading laadt relaties pas bij toegang, wat kan leiden tot prestatieproblemen. ```php // Lazy Loading - veroorzaakt N+1 Queries $posts = Post::all(); foreach ($posts as $post) { echo $post->author->name; // Elke toegang = 1 Query } // Eager Loading - slechts 2 queries totaal $posts = Post::with('author')->get(); foreach ($posts as $post) { echo $post->author->name; // Geen extra query } // Nested Eager Loading $posts = Post::with(['author', 'comments.user'])->get(); // Conditional Eager Loading $posts = Post::with(['comments' => function ($query) { $query->where('approved', true)->orderBy('created_at', 'desc'); }])->get(); ``` ### Hoe implementeer je polymorfe relaties? Polymorfe relaties stellen een model in staat om tot meerdere andere modellen te behoren. Een typisch voorbeeld zijn comments die zowel bij posts als bij video's kunnen horen. ```php // Migration voor polymorfe tabel Schema::create('comments', function (Blueprint $table) { $table->id(); $table->text('body'); $table->morphs('commentable'); // Creëert commentable_type en commentable_id $table->timestamps(); }); // Comment Model class Comment extends Model { public function commentable(): MorphTo { return $this->morphTo(); } } // Post Model class Post extends Model { public function comments(): MorphMany { return $this->morphMany(Comment::class, 'commentable'); } } // Video Model class Video extends Model { public function comments(): MorphMany { return $this->morphMany(Comment::class, 'commentable'); } } // Gebruik $post->comments()->create(['body' => 'Geweldig artikel!']); $video->comments()->create(['body' => 'Fantastische video!']); ``` ### Wat zijn Eloquent Accessors en Mutators in Laravel 11+? Met Laravel 11 wordt het `Attribute` Cast-patroon gebruikt voor Accessors en Mutators, wat een duidelijkere syntax biedt. ```php use Illuminate\Database\Eloquent\Casts\Attribute; class User extends Model { // Accessor en Mutator gecombineerd protected function firstName(): Attribute { return Attribute::make( get: fn (string $value) => ucfirst($value), set: fn (string $value) => strtolower($value), ); } // Computed Attribute (alleen Accessor) protected function fullName(): Attribute { return Attribute::make( get: fn () => "{$this->first_name} {$this->last_name}", ); } // Met caching voor dure berekeningen protected function profileScore(): Attribute { return Attribute::make( get: fn () => $this->calculateProfileScore(), )->shouldCache(); } } ``` ## Queue-systemen en Achtergrondverwerking ### Hoe werkt het Laravel Queue-systeem? Laravel Queues maken het mogelijk om tijdrovende taken uit te voeren in achtergrondprocessen. Het systeem ondersteunt verschillende drivers zoals Redis, Database en Amazon SQS. ```php // Job-klasse definiëren class ProcessPodcast implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public function __construct( public Podcast $podcast, ) {} public function handle(AudioProcessor $processor): void { $processor->process($this->podcast); } // Retry-configuratie public int $tries = 3; public int $backoff = 60; // Timeout definiëren public int $timeout = 120; // Foutafhandeling public function failed(Throwable $exception): void { // Notificatie sturen of loggen } } // Job dispatchen ProcessPodcast::dispatch($podcast); // Met vertraging ProcessPodcast::dispatch($podcast)->delay(now()->addMinutes(10)); // Op specifieke queue ProcessPodcast::dispatch($podcast)->onQueue('podcasts'); ``` ### Wat zijn Job Batches en hoe worden ze gebruikt? Job Batches maken het mogelijk om meerdere jobs te groeperen met gedeelde voortgangsregistratie en callbacks. ```php use Illuminate\Bus\Batch; use Illuminate\Support\Facades\Bus; $batch = Bus::batch([ new ProcessPodcast($podcast1), new ProcessPodcast($podcast2), new ProcessPodcast($podcast3), ])->then(function (Batch $batch) { // Alle jobs succesvol voltooid Log::info('Batch completed successfully'); })->catch(function (Batch $batch, Throwable $e) { // Eerste fout in de batch Log::error('Batch failed', ['error' => $e->getMessage()]); })->finally(function (Batch $batch) { // Batch voltooid (met of zonder fouten) })->allowFailures()->dispatch(); // Batch-status opvragen $batch = Bus::findBatch($batchId); echo $batch->progress(); // Voortgang in procent echo $batch->pendingJobs; // Wachtende jobs ``` ### Hoe implementeer je Rate Limiting voor queues? Rate Limiting voorkomt overbelasting van externe API's of resources door gecontroleerde job-uitvoering. ```php use Illuminate\Queue\Middleware\RateLimited; use Illuminate\Support\Facades\RateLimiter; // Rate Limiter definiëren (in AppServiceProvider) RateLimiter::for('api-requests', function (object $job) { return Limit::perMinute(60)->by($job->user->id); }); class SendApiRequest implements ShouldQueue { // Middleware toepassen public function middleware(): array { return [new RateLimited('api-requests')]; } public function handle(): void { // API-verzoek versturen } // Job terug in queue bij rate limit public function retryUntil(): DateTime { return now()->addHours(1); } } ``` ## Service Container en Dependency Injection ### Hoe werkt de Laravel Service Container? De Service Container is het hart van Laravel en beheert klasseafhankelijkheden via Dependency Injection. ```php // Interface definiëren interface PaymentGatewayInterface { public function charge(int $amount): PaymentResult; } // Implementatie class StripePaymentGateway implements PaymentGatewayInterface { public function __construct( private string $apiKey, ) {} public function charge(int $amount): PaymentResult { // Stripe-logica } } // Binding in ServiceProvider public function register(): void { // Simple Binding $this->app->bind(PaymentGatewayInterface::class, StripePaymentGateway::class); // Binding met configuratie $this->app->bind(PaymentGatewayInterface::class, function ($app) { return new StripePaymentGateway( apiKey: config('services.stripe.secret'), ); }); // Singleton voor enkele instantie $this->app->singleton(StripePaymentGateway::class); } // Gebruik in Controller class PaymentController extends Controller { public function __construct( private PaymentGatewayInterface $gateway, ) {} public function charge(Request $request): JsonResponse { $result = $this->gateway->charge($request->amount); return response()->json($result); } } ``` ### Wat is Contextual Binding? Contextual Binding maakt verschillende implementaties mogelijk afhankelijk van de gebruikscontext. ```php // Verschillende implementaties per controller $this->app->when(PhotoController::class) ->needs(Filesystem::class) ->give(function () { return Storage::disk('photos'); }); $this->app->when(VideoController::class) ->needs(Filesystem::class) ->give(function () { return Storage::disk('videos'); }); // Met primitieven $this->app->when(ReportGenerator::class) ->needs('$format') ->give('pdf'); ``` ## Architectuurpatronen en Best Practices ### Hoe implementeer je het Repository Pattern in Laravel? Het Repository Pattern abstraheert de data-toegangslaag en verbetert testbaarheid en onderhoudbaarheid. ```php // Interface interface UserRepositoryInterface { public function find(int $id): ?User; public function findByEmail(string $email): ?User; public function create(array $data): User; public function update(User $user, array $data): User; public function delete(User $user): bool; } // Eloquent-implementatie class EloquentUserRepository implements UserRepositoryInterface { public function __construct( private User $model, ) {} public function find(int $id): ?User { return $this->model->find($id); } public function findByEmail(string $email): ?User { return $this->model->where('email', $email)->first(); } public function create(array $data): User { return $this->model->create($data); } public function update(User $user, array $data): User { $user->update($data); return $user->fresh(); } public function delete(User $user): bool { return $user->delete(); } } // Service-klasse gebruikt Repository class UserService { public function __construct( private UserRepositoryInterface $repository, private HashManager $hash, ) {} public function registerUser(array $data): User { $data['password'] = $this->hash->make($data['password']); return $this->repository->create($data); } } ``` ### Wat zijn Actions en hoe structureer je complexe bedrijfslogica? Actions zijn Single-Responsibility-klassen voor complexe bedrijfsoperaties. Ze verbeteren testbaarheid en herbruikbaarheid. ```php class CreateOrderAction { public function __construct( private OrderRepository $orders, private InventoryService $inventory, private PaymentGatewayInterface $payment, private NotificationService $notifications, ) {} public function execute(User $user, Cart $cart, PaymentMethod $method): Order { // Inventaris controleren $this->inventory->checkAvailability($cart->items); // Betaling verwerken $paymentResult = $this->payment->charge( amount: $cart->total, method: $method, ); // Bestelling aanmaken $order = $this->orders->create([ 'user_id' => $user->id, 'total' => $cart->total, 'payment_id' => $paymentResult->id, 'items' => $cart->items->toArray(), ]); // Inventaris bijwerken $this->inventory->decrementStock($cart->items); // Notificaties versturen $this->notifications->orderCreated($order); return $order; } } // Gebruik in Controller class OrderController extends Controller { public function store( StoreOrderRequest $request, CreateOrderAction $action, ): JsonResponse { $order = $action->execute( user: $request->user(), cart: $request->user()->cart, method: $request->paymentMethod(), ); return response()->json($order, 201); } } ``` ### Hoe implementeer je Event Sourcing-concepten in Laravel? Event Sourcing slaat toestandswijzigingen op als gebeurtenissen, wat volledige audit trails en time-travel mogelijk maakt. ```php // Event definiëren class OrderPlaced { public function __construct( public string $orderId, public array $items, public int $total, public Carbon $occurredAt, ) {} } // Event Store class EventStore { public function append(string $aggregateId, object $event): void { DB::table('events')->insert([ 'aggregate_id' => $aggregateId, 'event_type' => get_class($event), 'payload' => json_encode($event), 'occurred_at' => now(), ]); } public function getEvents(string $aggregateId): Collection { return DB::table('events') ->where('aggregate_id', $aggregateId) ->orderBy('occurred_at') ->get() ->map(fn ($row) => unserialize($row->payload)); } } // Aggregate reconstrueren class Order { private array $items = []; private string $status = 'pending'; public static function reconstitute(Collection $events): self { $order = new self(); foreach ($events as $event) { $order->apply($event); } return $order; } private function apply(object $event): void { match (get_class($event)) { OrderPlaced::class => $this->applyOrderPlaced($event), OrderShipped::class => $this->applyOrderShipped($event), default => null, }; } } ``` ## Conclusie Laravel-sollicitatiegesprekken in 2026 vereisen diepgaande kennis van Eloquent ORM met geavanceerde functies zoals polymorfe relaties en het nieuwe Attribute Casting. Queue-systemen met Batches en Rate Limiting zijn essentieel voor schaalbare applicaties. De Service Container en Dependency Injection vormen het fundament voor testbare, onderhoudbare architecturen. Repository Pattern, Action-klassen en Event Sourcing-concepten demonstreren architectureel denken op senior niveau. Het beheersen van deze concepten met praktische codevoorbeelden onderscheidt succesvolle kandidaten van de rest. --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/nl/blog/laravel/php-laravel-framework-interview-questions-eloquent-queues-architecture