1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to build a relationship in Laravel with an altered column value

Discussão em 'Outras Linguagens' iniciado por Стрэлок Виамонтэ, Setembro 27, 2024 às 16:13.

  1. this is my first question in StackOverflow. I am here because I am trying to build a particular relationship in Laravel. I would like to be able to make something like THIS

    public function game()
    {
    $original_game_name = preg_replace('/\s+BONUS.(\s+|\d+)+/', '', $this->game);

    //I would like to use the current table game column modified to match the value at $original_game_name for the relationship. SOmething like:
    //return $this->hasOne('VanguardLTE\Game', 'name', $orginal_game_name);

    return $this->hasOne('VanguardLTE\Game', 'name', 'game');
    }


    I want it to be a relationship so I can eager load this relationship if needed easily usign "with".

    I tried putting $orginal_game_name directly in third argument of the hasOne method, and of course that didn't work since it accepts a column name. I thought about using a Query Building but I am kinda lost to what would be the way to use it in this case.

    Continue reading...

Compartilhe esta Página