samedi 25 mai 2019

Laravel Relation returning null result

My Laravel relation is returning a null result. Can anyone help what i am doing wrong.

Model code is :

public function title()
{
    $branch_id=session()->get('lbranch','0');
    return $this->hasOne('App\Accounts','code','supp_code')
        ->select('title')->where('branchid','=',$branch_id);
}

and Controller code is :

   $data = Purchase::with('title')
       ->where('purchases.branchid',$branch_id)
       ->select('purchases.*',
           DB::raw('(CASE 
                WHEN purchases.posted = "1" THEN "Posted" 
                ELSE "Unposted" 
                END) AS status'))
       ->latest()->get();

the queries generated are :

select `purchases`.*, (CASE
     WHEN purchases.posted = "1" THEN "Posted"
     ELSE "Unposted"
     END) AS status from `purchases` 
     where `purchases`.`branchid` = 22 order by `created_at` desc

select `title` from `accounts` where `branchid` = 22 and `accounts`.`code` in (100)



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/30EREm5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire