Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Trying to update attribute result in mass-update [Laravel 5]

I'm trying to change a value in my DB for a single item, I use first() to get an item, but for some reason when I try this function, every entry with the same primary key has the authenticated user gets the attribute 'AreFriend' updated at 1, why?

public function acceptrequest($id)
{
     $user = app('Dingo\Api\Auth\Auth')->user();
     if (!$targetuser = User::find($id)) {
         return response()->json(['status' => "The requested resource does not exists!"], 403);
     }
     if ($relation = $user->requestspending()->where('user_id', $targetuser->user_id)->first()) {
         Friend::unguard();
         $relation->AreFriend = 1;
         $relation->save();
         Friend::unguard();
         Friend::reguard();
         return response()->json(['status' => "Request accepted!"], 200);
     } else {
            return response()->json(['status' => "You do not have an invitation from this user!"], 403);
     }
}

In my database, relations with the $user id are updated. The variable $relation is an item, not a collection.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!