php - array/object to string conversion in laravel 6 query builder
Get the solution ↓↓↓"userS": {
"email": "[email protected]",
"name": "jack"
}
Above is array of object in my laravel 6. it is stored insession array
i want to use email so i am doing this
$sessionUser=Session::get('userS');
$sessionEmail=$sessionUser['email'];
it gives me email properly in string.
so i am finding the user ID inuser table
who have thisemail
following query givesuid
in array/object fromat
$uid=customerModel::where('email',$sessionEmail)->pluck('uid');
or
$uid=DB::select('select uid from user where email=:Email',['Email'=>$sessionEmail]);
but it gives me[1]
or[{"uid":1}]
(here 1 is uid which i want to use but it is in array format)
when i insert all records then it gives me following error
Incorrect integer value: '[1]' for columnecart
.tblorder
.uid
at row 1 (SQL: insert intotblorder
(uid
,pid
,quantity
,customer_name
,customer_email
,customer_mobile
,pincode
,address
,date
) values ([1], 2, 2, john, [email protected], 7458965874, 123456, testXYZ, 2020-06-29 13:01:40))
i wantsimple uid
not in array or object fromat
my sql query should be like
SQL: insert into `tblorder` (`uid`, `pid`, `quantity`, `customer_name`, `customer_email`, `customer_mobile`, `pincode`, `address`, `date`) values (1, 2, 2, john, [email protected], 7458965874, 123456, testXYZ, 2020-06-29 13:01:40)
Answer
Solution:
You can use the function to get a single value from the first record of the result set from the database:
$uid = customerModel::where('email', $sessionEmail)->value('uid');
Answer
Solution:
You can use
$uid=customerModel::select('uid')->where('email',$sessionEmail)->first()->uid;
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string deprecated
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.