[Solved] How to print key value pair in Laravel using foreach loop [closed]

Your code is a mess. here is a cleaner version without using the models (since you did not say if they are in place) Controller Code public function show_friend_request() { $user_id = auth()->user()->id; $senderIds = DB::table(‘friendships’)->where(‘recipient_id’, $user_id)->where(‘status’, ‘pending’)->pluck(‘sender_id’)->toArray(); $activeRequests = DB::table(‘users’) ->whereIn(‘id’, $senderIds) ->get([‘first_name’,’last_name’]); return view(‘pages.friend_request’)->with(‘activeRequest’, $activeRequests); } Blade Code @foreach($activeRequest as $key => $friend) … Read more

[Solved] Printing key value pair in Laravel blade using for each loop [closed]

Your code is a mess. here is a cleaner version without using the models (since you did not say if they are in place) Controller Code public function show_friend_request() { $user_id = auth()->user()->id; $senderIds = DB::table(‘friendships’)->where(‘recipient_id’, $user_id)->where(‘status’, ‘pending’)->pluck(‘sender_id’)->toArray(); $activeRequests = DB::table(‘users’) ->whereIn(‘id’, $senderIds) ->get([‘first_name’,’last_name’]); return view(‘pages.friend_request’)->with(‘activeRequest’, $activeRequests); } Blade Code @foreach($activeRequest as $key => $friend) … Read more

[Solved] How to Convert this sql query into laravel query builder

$result = DB::table(‘table as t’) ->select(‘t.product_id’, ‘t.on_hand’, ‘t.created_at’) ->join(DB::raw(‘(SELECT MAX(purchase_id) as pId FROM table Group by product_id) tg’), function($join) { $join->on(‘t.purchase_id’, ‘=’, ‘tg.pId’); })->get(); 1 solved How to Convert this sql query into laravel query builder

[Solved] Trying to get property of non-object (View: C:\xampp\htdocs\enginepoker2\resources\views\pages\player_edit.blade.php)

Generally this “Trying to get property of non-object” error is occurred while trying to access an array as an object. Make sure all the retrieved data from table are not array. 4 solved Trying to get property of non-object (View: C:\xampp\htdocs\enginepoker2\resources\views\pages\player_edit.blade.php)

[Solved] How to pass (start = date1) || (start = date2) condition in laravel

You can use where statement like the following: $events = DB::table(‘christophheich_calendar_entries’) ->where(function($q) use($date1, $date2) { $q->where(function($q2) use($date1) { $q2->where(‘start’, ‘<=’, $date1)->where(‘end’, ‘>=’, $date1); })->orWhere(function($q2) use($date2) { $q2->where(‘start’, ‘<=’, $date2)->where(‘end’, ‘>=’, $date2); }); }) ->whereNull(‘deleted_at’); This is how to create a where clause with a inner query that handles the or part of the where. Make … Read more

[Solved] Laravel Eloquent the same queries

In Either one of the code above, the query will just be 1 $a = Flight::find(1); is same as select * from `flights` where `flights`.`id` = 1 limit 1` Since $a & $b are 2 different variables, though they are calling the same Eloquent function, the queries are different. So the code above will result … Read more