Product.php
app/Models/Product.php
Eloquent Model: Product
This file defines the Product Eloquent Model. It represents the products table and provides mass assignment, type casting, and factory support.
Implementation
// filepath: app/Models/Product.php <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Product extends Model { use HasFactory; protected $fillable = [ 'name', 'description', 'price', 'stock', ]; protected $casts = [ 'price' => 'float', 'stock' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; }
💡
Key Features
• Mass assignment protection via $fillable
• Attribute casting for price and stock
• Factory support for testing and seeding
• Extends Laravel's Model base class