Laravel Voyager Scope use Parameter from Relationship

1.1k Views Asked by At

I have a question regarding Voyager Laravel Admin (BREAD).

I have a relation ship (ads - belongsTo -> game). And the ads have many types, and the types have also a game parameter. In Voyager it works, i can select a type for the ads. But i want only the types displayed, that are from the same game as the ad. I thought about scope, and i have a function like:

public function scopeGame($query, $game_id)
{
    return $query->where("game_id", $game_id);
}

In Voyager admin:

{
    "scope": "game"
}

But i need to pass the game_id. Does anyone know if this is posible and how?

1

There are 1 best solutions below

0
On

Modify the scope property in your BREAD config:

{
    "scope": [
        "game",
        {
            "key": "game_id",
            "value": "{{ $game_id }}"
        }
    ]
}

Use it in the "scopeGame"-function:

public function scopeGame($query, $game_id)
{
    return $query->where("game_id", $game_id);
}