Basic search
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
17
app/Http/Controllers/IkeaProductsController.php
Normal file
17
app/Http/Controllers/IkeaProductsController.php
Normal 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);
|
||||
}
|
||||
}
|
||||
35
app/Models/IkeaProducts.php
Normal file
35
app/Models/IkeaProducts.php
Normal 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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user