0
"userS": {
   "email": "[email protected]",
    "name": "jack"
}

Above is array of object in my laravel 6. it is stored in session 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 in user table who have this email

following query gives uid 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 column ecart.tblorder.uid at row 1 (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))

i want simple 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)

2 Answers 2

1

You can use the value() function to get a single value from the first record of the result set from the database:

$uid = customerModel::where('email', $sessionEmail)->value('uid');
Sign up to request clarification or add additional context in comments.

Comments

1

You can use

$uid=customerModel::select('uid')->where('email',$sessionEmail)->first()->uid;

Comments

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.