Mysql Laravel 6更新函数中的SQLSTATE[42S22]错误
我试图在我的laravel应用程序中运行更新功能,但每次运行该功能时,它都会给我此错误Mysql Laravel 6更新函数中的SQLSTATE[42S22]错误,mysql,laravel,laravel-5,eloquent,laravel-6,Mysql,Laravel,Laravel 5,Eloquent,Laravel 6,我试图在我的laravel应用程序中运行更新功能,但每次运行该功能时,它都会给我此错误 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update `apps` set `domain` = Testinput.test.com, `apps`.`updated_at` = 2020-03-30 13:18:32 where `id` is null) 这是我在控制器中的更
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update `apps` set `domain` = Testinput.test.com, `apps`.`updated_at` = 2020-03-30 13:18:32 where `id` is null)
这是我在控制器中的更新功能
public function update(Request $request,App $app, $id)
{
$this->validate($request, [
'domain' => ['required', 'string','min:2', 'max:255'],
],$request->all());
$fullDomain = $request->domain;
$app->domain=$fullDomain;
$app = App::where('appId','=','1')->first()->update($request->all());
return Redirect::back()->with('success',__('sentence.User updated successfully'));
}
我的应用程序表中没有名为id的列我的列是appId您必须通知Laravel您使用的主键与预期的主键不同: 在应用程序模型中,添加$primaryKey属性以及您在数据库中使用的主键的名称:
class App extends Model
{
protected $primaryKey = 'appId';
}
旁注,您不需要->第一->更新,只需执行->更新,重定向::返回可以更改为仅返回