All the examples of Eloquent Models in Laravel 4 extends Eloquent, but when you generate a Model in Laravel 5 it says extends Model, are they the same?
Laravel 4
<?php
class User extends Eloquent {
//Code
}
Laravel 5
<?php
class User extends Model {
//Code
}
The Laravel 5 docs says:
Defining An Eloquent Model
class User extends Model {}
Eloquent is an object relational mapper (ORM) that is included by default within the Laravel framework. An ORM is software that facilitates handling database records by representing data as objects, working as a layer of abstraction on top of the database engine used to store an application's data.
Some of the features due to which it is famous are Soft deleting, Timestamps, ActiveRecord implementation, multiple database handling, eager loading, model observers, model events, and much more. Eloquent relationships are the same as the method in Eloquent model classes.
Laravel Create Model is an MVC based PHP system. In the MVC architecture, 'M' stands for 'Model'. A model is used as a way for questioning data to and from the table within the database. Laravel gives a basic way to do that using Eloquent ORM where each table incorporates a Model to interact with it.
This allows you to add conditions throughout your code until you actually want to fetch them, and then you would call the get() function.
Yes they are the same. Laravel 4 uses Class Aliasing to map Illuminate\Database\Eloquent\Model
to Eloquent
. You can see in the app/config/app.php
file:
'Eloquent' => 'Illuminate\Database\Eloquent\Model',
Laravel 5 uses namespacing instead. So at the top of the model class you will see this line:
use Illuminate\Database\Eloquent\Model;
used...
use Illuminate\Database\Eloquent\Model;
to extend the model
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With