简体   繁体   English

雄辩的ORM无法在Laravel中保存价值

[英]Eloquent ORM not save value in laravel

I want to update my data using Eloquent but it gave me some error: 我想使用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)

Here is my code: 这是我的代码:

$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();

Please find where I do wrong in this code 请找到我在此代码中做错的地方

Because your primary key column is not called id (which is the default Laravel assumes) you have to specify it in your model: 因为您的主键列未称为id (这是Laravel假定的默认值),所以您必须在模型中指定它:

class Logo extends Eloquent {
    protected $primaryKey = 'logo_id';
}

Quote from the docs : 文档引用:

Note: Eloquent will also assume that each table has a primary key column named id. 注意:Eloquent还将假设每个表都有一个名为id的主键列。 You may define a primaryKey property to override this convention. 您可以定义primaryKey属性以覆盖此约定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM