Laravel

Eloquent Advanced

Query scopes, local scopes, global scopes, observers, events, collections methods, custom casts, attribute casting

24 mülakat soruları·
Senior
1

What is a local scope in Eloquent?

Cevap

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.

2

How to define a local scope named 'active' in an Eloquent model?

Cevap

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.

3

What is a global scope in Eloquent?

Cevap

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.

4

How to temporarily remove a global scope from a query?

5

What is a model observer in Laravel?

+21 mülakat soruları

Bir sonraki mülakatın için Laravel'de uzmanlaş

Tüm sorulara, flashcards'a, teknik testlere, code review alıştırmalarına ve mülakat simülatörlerine eriş.

Ücretsiz başla