Model đại diện cho bảng database theo cách hướng đối tượng. Tạo bằng php artisan make:model User. Các property: protected $table (override tên bảng), protected $fillable (cột được mass-assign như name, email), protected $hidden (loại khỏi output như password), protected $casts (ép kiểu như created_at thành date).
Ví dụ: $user = User::create(["name" => "John", "email" => "john@example.com"]); tạo bản ghi. Mass assignment yêu cầu mảng $fillable để bảo mật—ngăn gán các trường nhạy cảm. Model kết nối cấu trúc database với code PHP.
Models represent database tables in object-oriented way. Create with php artisan make:model User. Properties: protected $table (override table name), protected $fillable (mass-assignable columns like name, email), protected $hidden (exclude from output like password), protected $casts (type casting like created_at as date).
Example: $user = User::create(["name" => "John", "email" => "john@example.com"]); creates record. Mass assignment requires $fillable array for security—prevents assigning sensitive fields. Models connect database structure to PHP code.