Support the ongoing development of Laravel.io →
posted 8 years ago
Eloquent
Last updated 10 months 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 10 months ago.
0

You could take advantage of Eloquent model events:

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

Sign in to participate in this thread!

LaraJobs

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.

© 2023 Laravel.io - All rights reserved.