Laravel,如何消除下拉选择的一些“采摘”值?

时间:2018-01-21 16:42:34

标签: php sql laravel

控制器

thing = "string"
def my_func():
    a = input("Type something."))
    return a
>>>thing = my_func()
>>>Type something: Hello world
>>>print(thing)
>>>'Hello world'

enter image description here

表格

enter image description here

如您所见,代码返回“furnitures”表中的所有值,如何消除pluck查询结果中“furniture_prices”表中包含的值?所以在这种情况下,用户可以选择“fur5”,“fur6”,“fur8”,“fur9”,“fur10”,“fur11”和fur12“

1 个答案:

答案 0 :(得分:2)

我假设您已经定义了关系。使用doesntHave()方法:

Furniture::where('active', 1)->doesntHave('furniturePrices')->pluck('fur_name', 'id');

如果关系尚不存在,请先创建hasOne()hasMany()关系:

public function furniturePrices()
{
    return $this->hasMany(FurniturePrice::class, 'fur_id');
}