[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] Laravel 8: Missing required parameter for [Route: edit.question] [URI: editquestion/{question}] [Missing parameter: question]

From public function editQuestion(Question $slug) { return view(‘questions.editquestion’,[ ‘slug’ => $slug ]); } you are injecting Question model in editQuestion(Route-model binding), so you should pass your question class instance in your form too. <form action=”{{ route(‘edit.question’, $show) }}”> <button type=”submit” class=”text-blue-500″>Edit Question</button> </form> or <form action=”{{ route(‘edit.question’, [‘question’ => $show]) }}”> should work fine. solved … Read more