简体   繁体   中英

get data of rows that are not set as foreign key in Laravel

I want to get data of rows from a table that are not set as foreign keys in the related table. Please guide me on this in Laravel. I have used this but it's returning all data

$pages = DB::table('client_requests')
                ->leftJoin('bid_requests', 'client_requests.id', '=', 'bid_requests.client_request_id')
                ->select('client_requests.*')
                ->orderBy('created_at', 'DESC')
                ->paginate(20);

Thanks every one for your support. The problem was solved. This is the solution. It will be helpful for anyone with same issue. To get rows of data that is not set as foreign key in related table this is the way to get it in laravel.

$pages = DB::table('client_requests')
                ->leftJoin('bid_requests', 'client_requests.id', '=', 'bid_requests.client_request_id')
                ->select('client_requests.*')
                ->where('bid_requests.client_request_id','=',null)
                ->orderBy('created_at', 'DESC')
                ->get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM