【问题标题】:Eloquent ORM not save value in laravel雄辩的 ORM 不能在 laravel 中保存价值
【发布时间】:2015-04-12 07:35:52
【问题描述】:

我想使用 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还是别的什么?
  • 我的主键叫 logo_id

标签: php laravel laravel-4 orm eloquent


【解决方案1】:

因为您的主键列不称为 id(这是 Laravel 的默认设置),您必须在模型中指定它:

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

引用自docs

注意:Eloquent 还会假设每个表都有一个名为 id 的主键列。您可以定义一个 primaryKey 属性来覆盖此约定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-22
    • 1970-01-01
    • 2019-05-04
    • 2015-01-15
    • 2014-04-14
    • 2018-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多