This commit is contained in:
@@ -10,8 +10,8 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class IkeaProductsController extends Controller
|
||||
{
|
||||
public function search(Request $request, string $item)
|
||||
public function search(Request $request, string $item, string $country = '')
|
||||
{
|
||||
return IkeaProducts::search($item);
|
||||
return IkeaProducts::search($item, $country);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,18 @@ class IkeaProducts extends Model
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
protected function search($item)
|
||||
protected function search($item,$country = '')
|
||||
{
|
||||
if (strlen($item) >= 2 && strlen($item) <= 5) {
|
||||
return $this->where('name', 'LIKE', $item . '%')->get();
|
||||
if (strlen($item) >= 2 && strlen($item) < 5) {
|
||||
$result = $this->where('name', 'LIKE', $item . '%');
|
||||
if ($country != '') $result = $result->where('country',$country);
|
||||
return $result->get();
|
||||
} else if (strlen($item >= 5)) {
|
||||
return $this->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%')->get();
|
||||
} else {
|
||||
return [];
|
||||
if ($country != '') $result = $this->where('country',$country);
|
||||
$result = $result->where(function ($query) use ($item) { $query->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%'); } );
|
||||
|
||||
return $result->get();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user