Models
An Eloquent model maps a table to application behavior.
What it is
An Eloquent model maps a table to application behavior.
When to use it
Use for conventional persistence and relationships.
Syntax
class Order extends Model { protected $fillable = ["reference", "total_cents"]; }Example
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
protected $fillable = ["reference", "total_cents"];
protected function casts(): array
{
return ["total_cents" => "integer", "paid_at" => "datetime"];
}
}Common mistakes
Never put user_id, role, or approved state in unrestricted client mass assignment.