Gruesome.
When displaying a DataGrid, there are conflicts among fields name between the main and related objects.
class ArticlesController extends BaseController
{
public function getIndex()
{
$grid = DataGrid::source(Article::with('author')); //same source types of DataSet
$grid->add('id', 'id', true); //field name, label, sortable
$grid->add('title', 'Title', true); //field name, label, sortable
$grid->add('{{ substr($body,0,20) }}...', 'Body'); //blade syntax with main field
$grid->add('{{ $author->fullname }}', 'Author'); //blade syntax with related field
$grid->edit('/admin/articles/edit', 'Edit', 'modify|delete'); //shortcut to link DataEdit actions
$grid->orderBy('id', 'desc'); //default orderby
$grid->paginate(10); //pagination
$title = 'dsds';
return View::make('admin/article/index', compact('title', 'grid'));
}
public function anyEdit()
{
$edit = DataEdit::source(new Article);
$edit->add('title', 'Title', 'text')->rule('required|min:5');
$edit->add('body', 'Body', 'textarea');
$edit->add('author_id', 'User', 'select')->options(User::lists("fullname",
"id"));
$edit->add('publication_date', 'Date', 'date')->format('d/m/Y', 'it');
$edit->add('photo', 'Photo', 'image')->move('uploads/demo/')->fit(240,
160)->preview(120,
80);
$edit->add('public', 'Public', 'checkbox');
$title = 'dsds';
return $edit->view('admin/article/edit', compact('title', 'edit'));
}
}
After a while, I've been able to trace down the issue: my users table has just two users, so all the articles with id > 2 trigger the bug.