尝试获取 属性 of non-object Laravel (获取字符串)

Trying to get property of non-object Laravel (get string)

我现在正在使用我的 "Update function"。

public function edit($id)
{
    $product = Inventory::find($id);
    return view('/update',compact('product')) ;
}

这是我 blade

中的查看按钮
<a href="{{ route('edit',$prod->id) }}"  class="btn btn-raised btn-primary btn-sm">
                view
            </a>

当我将它重定向到我的编辑时它起作用了 blade

但是当我将 $id 更改为 $prod_num

 public function edit($prod_num)
    {
        $product = Inventory::find($prod_num);
        return view('/update',compact('product')) ;
    }

我的 $id 是 bigInt 和主键(AU),而 $prod_num 是一个字符串。

如果我想寻找 prod_id

怎么办

谢谢

find() 方法将查找模型的主键。如果你想通过另一个属性获取记录,你可以使用 where()first():

$product = Inventory::where('prod_num', $prod_num)->first();