Zaheer
203
8
Laravel

Relation not working

Posted 1 month ago by Zaheer

Can someone help me why I am getting blank result. My Model relation :

    public function title()
    {
        return $this->hasOne('App\Accounts','code','supp_code')->where('Accounts.branchid','=','Purchases.branchid');
    }

My Controller :

           $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();

I am getting null for the 'title' column. Thanks in advance.

Please sign in or create an account to participate in this conversation.