【问题标题】:Find model using uuid in laravel7在 laravel 7 中使用 uuid 查找模型
【发布时间】:2022-11-10 21:16:14
【问题描述】:

这听起来微不足道,但我一直在寻找一段时间,但我没有找到合适的答案! 如何在我的控制器中使用 uuid 获取模型?我试过findwhere('uuid', $uuid) 但它总是得到一个空值!

代码

public function index()
{
    $uuid = '90236239-5f28-4d74-948e-eb6c921b323c';
    return User::where('uuid', $uuid)->first();

部分模型

use App\Traits\UuidTrait;

class Userextends BaseModel
{

    use UuidTrait;

    protected $casts = [
         'uuid' => EfficientUuid::class,
    ];
}

【问题讨论】:

    标签: uuid laravel-7


    【解决方案1】:

    解决者

    whereUuid($uuid)->first();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      • 2019-12-14
      • 1970-01-01
      • 2016-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多