Increase the value of a field

1

The code I have in the function is the following:

DB::table('projects')
     ->where('order', DB::raw("(select 'order' from projects)"))
     ->order + 1; 

The error that shows me is the following:

  

Undefined property: Illuminate \ Database \ Query \ Builder :: $ order

How can I correct it?

    
asked by Lluís Puig Ferrer 24.10.2017 в 16:45
source

1 answer

1

It is generally not a good idea to use order as the name of a field, because in some engines it is a reserved word.

Responding to your concern, you should use the increment method, available in the Query Builder and Eloquent, if you want to increase ALL the values in the order column (I changed the name to ordering in my example) ), the following syntax should work:

DB::table('projects')-->increment('ordering');

More information in the documentation: link

    
answered by 24.10.2017 / 16:51
source