Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extends Model == extends Eloquent?

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 {}
like image 233
Jonathan Solorzano Avatar asked Aug 05 '15 16:08

Jonathan Solorzano


People also ask

What is eloquent model in Laravel?

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.

What is the feature of eloquent ORM?

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.

What is model in Laravel?

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.

What does get () do in Laravel?

This allows you to add conditions throughout your code until you actually want to fetch them, and then you would call the get() function.


2 Answers

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;
like image 71
Patrick Stephan Avatar answered Oct 27 '22 17:10

Patrick Stephan


used...

use Illuminate\Database\Eloquent\Model;

to extend the model

like image 36
Kevin Damian Cifuentes Munera Avatar answered Oct 27 '22 17:10

Kevin Damian Cifuentes Munera