gpt4 book ai didi

php - laravel 将 find by id 更改为 find by customerid

转载 作者:行者123 更新时间:2023-12-02 04:23:04 25 4
gpt4 key购买 nike

laravel 身份验证系统默认使用 Id,但是假设您有一个包含许多表的更大数据库,您如何指定客户表

$user = User::where('name', '=', $name);

if($user->count()) {
$user=$user->first();

$user->status= 'super';

if($user->save()) {
return Redirect::route('home')
}

}

最佳答案

如果您的主键的命名与 id 不同,您可以在模型中配置列名称:

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

protected $primaryKey = 'customer_id';

}

一切尽在documentation :

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. Likewise, you may define a connection property to override the name of the database connection that should be used when utilizing the model.

关于php - laravel 将 find by id 更改为 find by customerid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28926842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com