Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel relationship order by

<?php
public function comments()
{
    return $this->hasMany('Comment')->orderBy('column');
}
// two
class User
{
    public function comments()
    {
        return $this->hasMany('Comment');
    }
}

class Controller
{
    public function index()
    {
        $column = Input::get('orderBy', 'defaultColumn');
        $comments = User::find(1)->comments()->orderBy($column)->get();

        // use $comments in the template
    }
}
Source by laracasts.com #
 
PREVIOUS NEXT
Tagged: #laravel #relationship #order
ADD COMMENT
Topic
Name
3+1 =