Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sesc360's avatar

Models vs. Classes

Dear all, I have a question regarding custom models and classes. Is there any difference, if I need to define a class, between:

class Food extends Model {
...
}

and:

class Food extends Eloquent {
...
}

At the moment I have two different versions of the same thing I think. I created a class to be used for handling my objects:

class Incident extends \Eloquent {

    use EventGenerator;

    public $id;
    public $user_id;
    public $type;
    public $incident_reference;
    public $incident_id;
    public $date;
    public $time;
    public $location;
    public $street;
    public $city;
    public $latitude;
    public $longitude;
    public $incident_archived;


    // Create Incident from mobile app MFN and save to database
    public function create($latLng) {
        $this->setLocationCoordinatesFromRequest($latLng);
    }

and a class with within the models folder:

class Incident extends Model {

    // the variable sets the table name
    protected $table = 'incidents';

    // Make mass assignment possible
    protected $fillable = ['incident_id', 'incident_reference', 'date', 'time', 'city', 'location', 'street', 'latitude', 'longitude', 'type'];

    // Configure timestamps
    public $timestamps = true;

    public function responders() {
        return $this->hasMany('App\Models\Responder');
    }
}

But I got the feeling that I could combine these? So putting all the methods and variables inside the latter one into the first one, and just use one? Or do they need to be separate? I was a little bit confused, as in the series "Commands and Events" are "Job" model is created but not in the model folder where usually the models are, but within the jobs folder.

Is there any difference? Does the class I made then need to extend Model or Eloquent to be used?

Thank you

0 likes
2 replies
sesc360's avatar

Oh I see... the actual class that I am extending is "Illuminate\Database\Eloquent\Model" which is aliased to "Eloquent". So I am already using the Model functionalities.

1 like

Please or to participate in this conversation.