
Eloquent ORM Basics
Models, CRUD operations, query builder, mass assignment, timestamps, soft deletes, accessors, mutators
1What naming convention does Eloquent use by default to deduce the table name from the model name?
What naming convention does Eloquent use by default to deduce the table name from the model name?
Câu trả lời
Eloquent uses the plural snake_case of the class name to deduce the table name. For example, the User model corresponds to the users table, and BlogPost corresponds to blog_posts. This convention can be overridden by defining the $table property in the model.
2Which Eloquent method allows creating AND saving a new model in a single operation?
Which Eloquent method allows creating AND saving a new model in a single operation?
Câu trả lời
The create() method allows creating and saving a model in a single operation by accepting an array of attributes. It requires attributes to be listed in the $fillable property or $guarded to be defined to protect against mass assignment. Unlike new Model() followed by save(), create() combines these two steps.
3What happens if attempting to mass assign an attribute that is not in $fillable?
What happens if attempting to mass assign an attribute that is not in $fillable?
Câu trả lời
Laravel throws a MassAssignmentException to protect against mass assignment vulnerabilities. This protection prevents malicious users from injecting unauthorized attributes via HTTP requests. You must either add the attribute to $fillable, use $guarded to protect only certain attributes, or use forceFill() to bypass protection.
What is the difference between the find() and findOrFail() methods in Eloquent?
How does Eloquent automatically handle the created_at and updated_at columns?
+19 câu hỏi phỏng vấn
Các chủ đề phỏng vấn Laravel khác
PHP Basics
PHP OOP Essentials
Composer & Autoloading
Laravel Fundamentals
Laravel Routing
Blade Templates
Request & Response
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
Eloquent Advanced
Repository Pattern
Laravel Packages
Performance Optimization
Security Best Practices
Laravel Octane
Laravel Distributed Systems
Observability & Monitoring
Deployment & DevOps
Nắm vững Laravel cho lần phỏng vấn tiếp theo
Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.
Bắt đầu miễn phí