Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update data with Eloquent without id in Laravel 4

When I want to update the FaqTrans database, but this datase have two primary key (faq_ida and lang) $table->primary(array('lang', 'faq_id'));. so I don't need a id column with auto_increment.

However, when I use the following code to update the database, the error message hint me there is no id column.

$faq_trans = FaqTrans::where('faq_id','=',$faq_id)->where('lang','=',$lang)->first();
$faq_trans->lang  = Input::get('lang');
$faq_trans->body  = Input::get('body');
$faq_trans->title = Input::get('title');
$faq_trans->save();

error message

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update FAQtrans set body = ?, updated_at = ? where id is null) (Bindings: array ( 0 => 'adfadaaadfadaa', 1 => '2013-07-04 11:12:42', ))

and when I added an id column, the code works fine...

are there any way can I update the database without ID column ?

like image 526
Eugene Wang Avatar asked Jul 04 '13 03:07

Eugene Wang


1 Answers

Write this line into your Model

public $primaryKey = '_id';

Where _id is your manual primary key

like image 148
Nishchit Avatar answered Oct 04 '22 17:10

Nishchit