ERROR: Object of class stdClass could not be converted to string
16,832
Solution 1
The problem is probably on this line:
$user->retailer_code = $retailer_code;
$retailer_code
is an object and you need to get the property of it like this:
$user->retailer_code = $retailer_code->retailer_code;
Solution 2
$retailer_code which is stdClass and you cannot use directly as variable ,
$retailer_code = DB::table('branches')->select('retailer_code')->where('id', $id)->first();
will returns the retailer_code so
$retailer_code->retailer_code //would be the solution.
Please refer this link.
Author by
Lumiere
Updated on July 31, 2022Comments
-
Lumiere almost 2 years
When I run the code below
$id = Input::get('branch_id'); $retailer_code = DB::table('branches')->select('retailer_code')->where('id', $id)->first(); $user = new User; $user->user_firstname = Input::get('user_firstname'); $user->user_lastname = Input::get('user_lastname'); $user->user_email = Input::get('user_email'); $user->username = Input::get('username'); $user->password = Hash::make(Input::get('password')); $user->position_id = Input::get('position_id'); $user->retailer_code = $retailer_code; $user->branch = Input::get('branch_code'); $user->status = "1"; $user->save(); return Redirect::to('admin/users')->with('message', 'New User Added!');
I get this error "Object of class stdClass could not be converted to string"