我想在laravel系统中编辑数据,该系统具有一个customer_id作为增量键。 但是错误显示,
Illuminate \ Database \ QueryException(42S22)SQLSTATE [42S22]:列 找不到:1054“ where子句”中的未知列“ customers.id”(SQL: 从
customers
中选择*,其中customers
。id
= 4个限制1)
以前的例外情况
SQLSTATE [42S22]:找不到列:1054未知列'customers.id' 在“ where子句”(42S22)
我不明白为什么。
我试图在模型中添加受保护的主键customer_id。 但是结果和以前一样。
这是我的控制器
{
$customer = \App\Customer_Model::find($customer_id);
$customer->delete();
return redirect('/customers')->with('sukses', 'Users has been deleted!');
}
这是我的模特
namespace App;
use Illuminate\Database\Eloquent\Model;
class Customer_Model extends Model
{
protected $table = 'customers';
protected $primarykey = 'customer_id';
protected $fillable = ['customer_id', 'customer_code', 'customer_name', 'email', 'phone', 'contact_person', 'address', 'user_id', 'created_by', 'updated_by', 'void'];
}```
This is my view
```<tbody>
@foreach($data_customer as $cust)
<tr>
<td>{{$cust->customer_code}}</td>
<td>{{$cust->customer_name}}</td>
<td>{{$cust->email}}</td>
<td>{{$cust->phone}}</td>
<td>{{$cust->contact_person}}</td>
<td>{{$cust->address}}</td>
<td><a href="/customers/{{$cust->customer_id}}/edit" class="btn btn-warning"><span class="icon-settings icons icon"></span></a><a href="/customers/{{$cust->customer_id}}/delete" class="btn btn-danger"><span class="icon-trash icons icon"></span></a></td>
</tr>
@endforeach
</tbody>```
答案 0 :(得分:0)
将$primarykey
更改为$primaryKey
。该变量区分大小写,Laravel正在寻找$primaryKey
(大写的“ K”)