dimanche 18 août 2019

couldn't get data using laravel eloquent

What I want is that when a user visits this link /api/bonus?provider[]=MyCompany the result will show only bonus provided by providers=[MyCompany].

In my controller:

public function all(Request $request)
{
    $size = $request->input('size');

    $bonus = Bonus::with('category', 'bonusRelease');
    $bonus = Filterer::apply($request, $size, $bonus);
}

Bonus

public function bonusRelease()
{
    return $this->hasMany(BonusRelease:class, 'fk_bonus_id', 'id');
}

Filterer

public static function apply(Request $filters, $size, $bonus)
{
     if ($filters->has('provider')) {
                $bonus->whereHas('bonusRelease', function ($bonus) use ($filters) {
                    $bonus->whereIn('providers', $filters->input('provider',[]));

                });
            }
}

but at the end I'm getting this result

enter image description here

migrations create_bonus_releases_table

   public function up()
    {
        Schema::connection('mydb')->create('bonus_releases', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->decimal('release_value', 18, 6);
            $table->json('providers');
            $table->bigInteger('fk_bonus_id')->unsigned();

            $table->foreign('fk_bonus_id')->references('id')->on('bonuses');
        });
    }

    public function down()
    {
        Schema::dropIfExists('bonus_releases');
    }
}

I'm wonder why I can't get the data. Which part I had done wrong?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Nd3UWE
via IFTTT

Aucun commentaire:

Enregistrer un commentaire