Mam mały problem z wyszukiwaniem w Laraverze. Projekt piszę w Laravel 8.
Mam takie modele / migracje:
class Category extends Model { use ScopeActiveTrait, NodeTrait, HasSlug, SoftDeletes; protected $guarded = ['id']; protected $fillable = [ 'category_name', 'description', 'keywords', 'content', 'enable', 'photo', 'order', 'slug', '_lft', '_rgt', 'parent_id', 'value' ]; public $timestamps = false; protected $dates = [ 'deleted_at' ]; protected $casts = [ 'order' => 'integer', 'enable'=>'boolean' ]; /** * Get the options for generating the slug. */ public function getSlugOptions() : SlugOptions { return SlugOptions::create() ->generateSlugsFrom('category_name') ->slugsShouldBeNoLongerThan(160) ->saveSlugsTo('slug'); } } public function up() { Schema::table('categories', function (Blueprint $table) { $table->text('value')->after('parent_id')->nullable(); }); } Schema::create('categories', function (Blueprint $table) { $table->id(); $table->string('category_name', 155); $table->string('description', 155)->nullable(); $table->string('keywords', 155)->nullable(); $table->longText('content')->nullable(); $table->boolean('enable')->default(false); $table->string('photo', 155)->nullable(); $table->bigInteger('order')->default(0); $table->string('slug', 160)->nullable(); $table->softDeletes(); NestedSet::columns($table); $table->engine = "InnoDB"; $table->charset = 'utf8mb4'; $table->collation = 'utf8mb4_unicode_ci'; });
Używam komponentu: kalnoy/nestedset - ale tutaj nie jest to istotne.
W kolumnie categories.value mam np. taką wartość:
AUDI - TT - 8N (1998-2006) - UKŁAD WYDECHOWY - ELEMENTY MOCUJĄCE
Kiedy próbuję wyszukać za pomocą funkcji:
public function getSelect2(Category $category, Request $request) { $categories = Category::select('id', 'value') ->where(function ($query) use ($request) { $query->orWhere('category_name', 'like', '%' . $request->search . '%'); $query->orWhere('description', 'like', '%' . $request->search . '%'); $query->orWhere('keywords', 'like', '%' . $request->search . '%'); $query->orWhere('content', 'like', '%' . $request->search . '%'); $query->orWhere('value', 'like', '%' . $request->search . '%'); })->active() ->orderby('order', 'asc') ->get(); foreach ($categories as $item) { "id" => $item->id, "text" => $item->value ); } return $response; } }
Np. : Audi - mam dużo wyników.
Kiedy wpiszę: 'audi układ' - nie mam żadnego wyniku

Jak to naprawić?