-
Notifications
You must be signed in to change notification settings - Fork 296
DataSet
Thom Hutter edited this page Feb 15, 2015
·
5 revisions
DataSet can paginate results starting from query, eloquent collection or multidimensional array.
It adds the ability to order result and keep persistence of all params in query string.
i.e.:
/dataset/uri?page=2&ord=-name will get page 2 order by "name" descending
/dataset/uri?page=3&ord=name&other=xx will get page 3 order by "name"
in a controller
//using table name
$dataset = DataSet::source("tablename")->paginate(10)->getSet();
//or using query
$dataset = DataSet::source(DB::table('users')->select('name', 'email'))
->paginate(10)->getSet();
//or using eloquent model or eloquent builder
$dataset = DataSet::source(new Article)->paginate(10)->getSet();
$dataset = DataSet::source(Article::with('author'))->paginate(10)->getSet();
//or using array
$dataset = DataSet::source($multidimensional_array)->paginate(10)->getSet();in a view you can use
<p>
//cycle
@foreach ($dataset->data as $item)
{{ $item->title }}<br />
{{ $item->author->name }}<br />
@endforeach
{{ $dataset->links() }} <br />
//sort link
{{ $dataset->orderbyLink('title', 'asc') }} <br />
</p>As you see you can build a dataset using "one row of code" (with chaining), however I suggest you this alternative syntax to be more in "standard" with other widgets:
$set = DataSet::source(Article::with('author'));
$set->paginate(10);
$set->build();
View::make('articles', compact('set'))presentation
editing