jeudi 8 novembre 2018

How can i make inner join in method instead of controller?

I have a two tables orders and product. Relation is One to One. In my order class i created method product

public function product() {
        return $this->hasOne('App\Product', 'key_id', 'key_id');
    }

Now in controller i want select rows where id is not null that's why i wanna use InnerJoin

Order::where('order_id', 7)
    ->join('products', 'products.key_id', 'orders.key_id')
    ->get();

That is fine but i would like get

Order::where('order_id', 7)->get();

and all join move to method like:

public function product() {
    return $this->hasOne('App\Product', 'key_id', 'key_id')
     ->join('products', 'products.key_id', 'orders.key_id')
}

How can i do this ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire