Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

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)))

Last updated 1 year ago.
0

You could take advantage of Eloquent model events:

Page::creating(function($page)
{
    $page->order = Page::max('order')+1;
});
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Albert221 albert221 Joined 13 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.