Eloquent relation without model

10,475

You are mixing up relationship definition and building query in here.

If you do not want to define another model then forget about hasOne() and use query builder with join like described here http://laravel.com/docs/5.0/queries#joins

Share:
10,475
Admin
Author by

Admin

Updated on June 05, 2022

Comments

  • Admin
    Admin almost 2 years

    Imagine we have two tables:

    products                product_langs
    ==============          ==============
       id                      id_product
       name                    lang
                               description
    

    Now I want to link these two tables together like:

    return $product->hasOne('App/ProductLang')
      ->where('id_product', '=', 'id')
      ->where('lang', '=', $lang);
    

    Is there an out of the box possibility to do this without having the Model App/ProductLang?