This:
$page = new \Page;
$page->fill(\Input::only('name', 'slug', 'content', 'type'));
$page->order = \DB::raw('MAX(order)+1');
Throws me error:
Illuminate \ Database \ QueryException (HY000)
SQLSTATE[HY000]: General error: 1 near "order": syntax error (SQL: insert into "pages" ("name", "slug", "content", "type", "order") values (tududu, tududu, <p>tamdam</p> , 0, (MAX(order)+1)))
You could take advantage of Eloquent model events:
Page::creating(function($page)
{
$page->order = Page::max('order')+1;
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community