Laravel eloquent - One to many relationships

后端 未结 2 1201
别那么骄傲
别那么骄傲 2021-02-04 21:50

I have just got started with laravel v3 and am trying to wrap my head around eloquent\'s One-To-Many relationships by creating a blog, I have posts that have a many to one relat

2条回答
  •  盖世英雄少女心
    2021-02-04 22:32

    Laravel 4 has a slightly different syntax , it uses camelCase to build expressions (while L3 uses snake_Case syntax).Laravel's (L4) new syntax is now PSR-1 compliant .

    L3 : $this->belongs_to('Category');
    L4 : $this->belongsTo('Category');
    

    To prove that "eager loading" boosts the performance of your application (by minimizing database queries) , use Laravel's event eco-system .

    // app/routes.php 
    Event::listen('illuminate.query', function($sql) { echo '

    ' . $sql . '

    ' ;});

    .

提交回复
热议问题