
Eloquent Advanced
Query scopes, local scopes, global scopes, observers, events, collections methods, custom casts, attribute casting
1What is a local scope in Eloquent?
What is a local scope in Eloquent?
Antwoord
Local scopes allow defining reusable query constraints in the model. They are declared with the scope prefix and called without it. This approach improves code readability and prevents duplication of filtering logic throughout the application.
2How to define a local scope named 'active' in an Eloquent model?
How to define a local scope named 'active' in an Eloquent model?
Antwoord
A local scope is defined with the scope prefix followed by the name in PascalCase. The method receives the query builder object and returns the same modified object. The scope is then called without the prefix, in camelCase, directly on the query builder.
3What is a global scope in Eloquent?
What is a global scope in Eloquent?
Antwoord
A global scope automatically applies a constraint to all queries on a model. It registers in the model's boot method and implements the Scope interface. This feature is useful for systematic filters like soft delete or multi-tenancy.
How to temporarily remove a global scope from a query?
What is a model observer in Laravel?
+21 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
API Resources & Authentication
Middleware
Service Container & DI
Queues & Jobs
Events & Listeners
Notifications & Mail
File Storage
Testing & PHPUnit
Caching
Livewire & Inertia
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