Eloquent ORM 未在 laravel 中保存值
Eloquent ORM not save value in laravel
我想使用 Eloquent 更新我的数据,但它给了我一些错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'od_logo.id' in 'where clause' (SQL: select * from `od_logo` where `od_logo`.`id` = 1 limit 1)
这是我的代码:
$logo = Logo::find($id);
$logo->logo_logoimg_name = Input::get('logo_name');
$logo->logo_logoimg_path = $logo_destinationPath . $logo_filename;
$logo->logo_faviconimg_name = $favicon_destinationPath . $favicon_filename;
$logo->save();
请找出我在这段代码中哪里做错了
因为您的主键列未被称为 id
(这是默认的 Laravel 假设)您必须在您的模型中指定它:
class Logo extends Eloquent {
protected $primaryKey = 'logo_id';
}
引自docs:
Note: Eloquent will also assume that each table has a primary key column named id. You may define a primaryKey property to override this convention.
我想使用 Eloquent 更新我的数据,但它给了我一些错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'od_logo.id' in 'where clause' (SQL: select * from `od_logo` where `od_logo`.`id` = 1 limit 1)
这是我的代码:
$logo = Logo::find($id);
$logo->logo_logoimg_name = Input::get('logo_name');
$logo->logo_logoimg_path = $logo_destinationPath . $logo_filename;
$logo->logo_faviconimg_name = $favicon_destinationPath . $favicon_filename;
$logo->save();
请找出我在这段代码中哪里做错了
因为您的主键列未被称为 id
(这是默认的 Laravel 假设)您必须在您的模型中指定它:
class Logo extends Eloquent {
protected $primaryKey = 'logo_id';
}
引自docs:
Note: Eloquent will also assume that each table has a primary key column named id. You may define a primaryKey property to override this convention.