So, i'm confused with this : In Laravel's official documentation, they say :
The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table.
Ok util here all is Great, i get it !
So I make a migration to create a database : php artisan make:migration create_items_table --create="items"
Great until here too :)
So theoretically speaking, when i will make : php artisan make:model Item , Laravel will create a php class ( which is used to interact with items table) :
class Item extends Eloquent {
...
}
But,in real world, when i make : php artisan make:model Item , Laravel creates php class ( which is used to interact with items table) ::
class Item extends Model {
...
}
So Why Model and not Eloquent ?? Am i missing sth ? And What's the difference between Eloquent Model and Model.
And if there's a difference, when should i use Eloquent and when Model ... ?
Thank you ^^
Eloquent is the name given to the ORM (Object-relational mapping) that ships with Laravel. Eloquent allows you to interact with your tables as though they were objects, however Eloquent is unaware of the actual columns you have on your table.
Let's consider the simple User model
. We want this model to query records on our users
table.
class User extends Eloquent {
protected $table = 'users';
} That there is a very simple model. Now, instead of querying like this.
$user = DB::table('user')->find(1);
You can query like this.
$user = User::find(1);
Eloquent itself uses its own query builder but does fall back to the standard query builder. This means it has all the methods on the query builder available to it, and more.
The benefits here are:
I've only touched on Eloquent. There is so much more to it. I suggest you take a look at the following resources.
For more exact simple example click here
I found the solution for my question ...
So Normally you must add an alias to your config/app.php
'aliases' => [
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
And when you create a model, Laravel will use Eloquent;
instead of use Illuminate\Database\Eloquent\Model;
this why i think, some person may use Model, when other may use Eloquent , it's just a matter of give a meaning sense to the namespace :3
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