
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?
Respuesta
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?
Respuesta
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?
Respuesta
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 preguntas de entrevista
Otros temas de entrevista Laravel
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
Domina Laravel para tu próxima entrevista
Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.
Empieza gratis