问题描述
我对 Laravel 很陌生
尝试按标签创建搜索系统,例如我有一个 products
表,每个产品在 product_tags
表中都有多个标签。 product_tags
表有两列 product_id
和 product_tag
$search = $req->get('search'); // Input from user
$products = Product::with(['images','tags'])
->where('id','LIKE','%'.$search.'%')
->orWhere('product_name','%'.$search.'%')
->orWhere('product_price','%'.$search.'%')
->get();
dd($products);
产品模态
class Product extends Model
{
use HasFactory;
public function images()
{
return $this->hasMany(ProductImage::class,'product_id','id')->orderBy('id','desc');
}
public function tags()
{
return $this->hasMany(ProductTag::class,'desc');
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)