0

I have a function that is taking an id as a param, and updates the db using the DB method. however, when i run the code, the variable is not being passed to the method. to test, i replaced $id with an integer and it worked, so i think the DB method can not access the variable from the parameter

public function disable($id)
{

    // Update the user status to 0 from 1
    DB::table('employees')->where('id', $id)->update(['status' => 0]);
    return redirect('/employee')->with('error', 'User is disabled, all related accounts are now shutdown!...');
}

Update: Forgot to mention that i have already checked, and the param comes inside the function OK, i can return the id outside of the method

SOLUTION As shown in the comment, the varDump was returning "id=9" where i need "9", i noticed in the form piece of my code, there was an extra "id=" before the id which caused a malfunction.

13
  • post the example of when when you call the method with a non-integer parameter Commented Aug 29, 2017 at 12:01
  • Is this function called in the request ? Commented Aug 29, 2017 at 12:01
  • i think your $id parameter is a string, so mysql is failed to match the id, convert it in an integer as $id=(int)$id;, then try Commented Aug 29, 2017 at 12:02
  • yes it's called in the request Commented Aug 29, 2017 at 12:02
  • call dd($id); in this function to check if $id is passed true Commented Aug 29, 2017 at 12:03

1 Answer 1

1

Use function as disable(Request $request) and get id as $request->id

public function disable(Request $request)
{
    // Update the user status to 0 from 1
    DB::table('employees')->where('id', $request->id)->update(['status' => 0]);
    return redirect('/employee')->with('error', 'User is disabled, all related accounts are now shutdown!...');
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, but didn't make a difference!. the weird thing is I can replace the $id with a static number from the DB and run, which updates. so I know the method is good, also, I can echo the $id after the method has run, so i know the $id is coming in too, but they don't talk to each other!
what you are getting in /storage/logs/laravel.log ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.