Basic search
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
2023-12-05 21:49:32 +01:00
parent d3801506da
commit 3cfa2e3513
5 changed files with 86 additions and 5 deletions

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers;
use App\Models\IkeaProducts;
use Illuminate\Http\Request;
use Illuminate\Http\Client\Pool;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use PhpParser\Node\Expr\Cast\String_;
class IkeaProductsController extends Controller
{
public function search(Request $request, string $item)
{
return IkeaProducts::search($item);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class IkeaProducts extends Model
{
use HasFactory;
protected $table = 't_ikea_products';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = null;
/**
* Indicates if the model's ID is auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
protected function search($item)
{
if (strlen($item) > 3) {
return $this->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%')->get();
} else {
return [];
}
}
}