Laravel 6 更新函数中的 SQLSTATE[42S22] 错误

SQLSTATE[42S22] error in Laravel 6 update function

我正在尝试 运行 我的 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)

这是我在控制器中的更新功能,

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 的列table我的列是 appId

您必须告知 Laravel 您使用的主键与预期的不同:

在您的 App 模型中添加 $primaryKey 属性 以及您在数据库中使用的主键的名称:

class App extends Model
{
    protected $primaryKey = 'appId';
}