Eloquent en Laravel

lunes, 12 de junio de 2017


Anotaciones sobre Eloquent en Laravel 5.

Modificar valores predeterminados de los modelos
namespace App;

use Illuminate\Database\Eloquent\Model;

class Usuario extends Model
{
    protected $table = 'tbl_usuario';
    $primaryKey = 'usuario_id';
    public $timestamps = false;
}
https://desarrolloweb.com/articulos/laravel-eloquent.html

Ordenar de acuerdo a la cantidad de elementos relacionados.
User::withCount('categories')->orderBy('categories_count', 'desc')->get(); 
https://stackoverflow.com/questions/24208502/laravel-orderby-relationship-count https://stackoverflow.com/questions/37516509/order-by-for-relationship-in-eloquent https://laracasts.com/discuss/channels/eloquent/eloquent-order-by-related-table https://laracasts.com/discuss/channels/general-discussion/eloquent-order-by-on-an-eager-loaded-relationships-foreign-key-relationship

ManyThrough con relaciones ManyToMany.
$books = Book::with('author.contacts')->get();
$books = App\Book::with('author.contacts','author.publishers')->get();
$client=Client::with('appointments.services')->get()
https://laracasts.com/discuss/channels/general-discussion/getmanythrough-with-manytomany https://stackoverflow.com/questions/35490728/laravel-eloquent-eager-load-multiple-nested-relationships https://laravel.io/forum/03-04-2014-hasmanythrough-with-many-to-many/ https://stackoverflow.com/questions/23788844/hasmanythrough-with-one-to-many-relationship/23789210#23789210


Mapear queries a modelos Eloquent (Hydrate Raw hasta 5.3 y FromQuery en 5.4)
$user=User::fromQuery('select * from users where id=:codigo', ['codigo'=>1]);
https://laracasts.com/discuss/channels/eloquent/raw-query-but-map-to-my-model
https://laravel.com/api/5.0/Illuminate/Database/Eloquent/Model.html#method_hydrateRaw
https://laravel.com/docs/5.4/upgrade

 -

Néstor Mercedes

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 comentarios:

Publicar un comentario