I cant figure out how assign variables in controller from array with database datas.
this line:
$user = User::where('id', $id)->first()->toArray();
dd($user)
return this:
array:3[
"id"=> 1
"name"="John"
"surname"="Wick"
]
how can assign variables from array?
$fullName = $name . $surname;
You can use extract
to extract array keys as PHP variables.
<?php
$user = User::where('id', $id)->first()->toArray();
extract($user);
$fullName = $name . " " . $surname;
echo $fullName;
Demo: https://3v4l.org/1IRRF
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.