mardi 1 octobre 2019

Laravel Eloquent Queries

I need help with Eloquent. When i tried searching for "manufacturer name" it returns nothing, but if i try searching for "manufacturer" or "name", it returns me some results.

My current table structure is:

Product:

  • manufacturer_id, FK id on manufacturer

  • model_id, FK id id on model

Manufacturer:

  • id
  • name

Model:

  • id
  • manufacturer_id, FK id on manufacturer
  • name

My code is as such:

    $q = Input::get("query");
    $words = str_replace(" ", "%", $q);

    $cars = Product::whereHas('model', function ($query) use ($words) {
        $query->where('name', 'like', "%$words%");
    })->orWhereHas('manufacturer', function ($query) use ($words) {
        $query->where('name', 'like', "%$words%");
    })->get();

Please help me, I'm really new at this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire