The difference between an Eloquent Model and a Model?

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 ^^

Answers


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


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:

  • You don't have to specify your table name on every call.
  • The code reads a whole lot better, it's syntactical sugar.
  • You can create complex relationships between tables and use eager loading.
  • You can make use of functionality such as mass assignment protection and setters/getter.

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


Need Your Help

Date range problems in Oracle. How do I correctly grab date ranges in this format?

sql oracle sql-date-functions

I have this Oracle database, and it has a list of dates in this format: mm/dd/yy 0:00:00 AM/PM (1 for January, instead of 01; 1 for the day, instead of 01, and so forth).

MVC 4 - Visitor auditing and tracking

asp.net-mvc vb.net asp.net-mvc-3 razor asp.net-mvc-4

Thought I would put this out there before I embark on my own research.