📜  laravel 搜索数据关系 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:50.993000             🧑  作者: Mango

代码示例1
$data = Subcategory::with(["category"])
                            ->where('name','like', '%'.$this->searchData.'%')
                            ->orWhereHas('category', function($query){$query->where('name', 'like', '%'.$this->searchData.'%');})
                            ->orderBy($this->orderByData, $this->orderByAsc ? 'asc' : 'desc')
                            ->paginate($this->showData);