douweinu8562 2015-02-11 19:20
浏览 15
已采纳

雄辩的ORM不会在laravel中节省价值

I want to update my data using Eloquent but it gave me some error:

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

  • 写回答

1条回答 默认 最新

  • dtvq4978 2015-02-11 19:28
    关注

    Because your primary key column is not called id (which is the default Laravel assumes) you have to specify it in your model:

    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. You may define a primaryKey property to override this convention.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlserver排序语句
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃