Laravel Show Resource搜索错误的列 [英] Laravel Show Resource searching wrong column

查看:60
本文介绍了Laravel Show Resource搜索错误的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的空间(属性)创建了一个模型和控制器,该模型和控制器具有数据库结构; space_id space_address space_owner space_price 等...

I have created a model and controller for my spaces (properties) which has the database structure of; space_id, space_address, space_owner, space_price etc...

但是,当我访问 localhost:8000/project/space/1 时,出现此错误:

However when I visit localhost:8000/project/space/1 I am getting this error:

未找到列:1054"where子句"中的未知列"spaces.id"(SQL:从 spaces where spaces . id = 3个限制1)

Column not found: 1054 Unknown column 'spaces.id' in 'where clause' (SQL: select * from spaces where spaces.id = 3 limit 1)

功能

public function show($id)
{
        $space = Space::find($id);
        return view('space.show')->with('space', $space);

}

这是我的模型,如果有帮助的话:

This is my model if this helps:

class Space extends Model
{
    protected $table = 'spaces';
    public $primarykey = 'space_id';
}

推荐答案

您应该使用

$primaryKey = 'space_id';

而不是:

$primarykey = 'space_id';

请注意区分大小写对于PHP中的变量名称:

Notice that the case sensitivity for the variables names in PHP:

PHP中的变量用美元符号表示,后跟变量名称.变量名称区分大小写.

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

这篇关于Laravel Show Resource搜索错误的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆