Reputation: 3751
I have many columns in my 'users' table. I want to show just one user's first name and last name from many others columns in front page pop-up for all. User name will be changed in every refresh randomly. Please, someone help me.I tried something like bellow--
<?php
$users = DB::table('users')
->select('first_name','last_name')
->inRandomOrder()
->get();
echo $users;
?>
It's showing all users and in key-value formatted.
Upvotes: 0
Views: 31
Reputation: 35200
Firstly, if you just want to show 1 user then use first()
instead of get()
.
Then to get the first name and last name you would just access the properties on the object e.g.
$user = DB::table('users')
->select('first_name', 'last_name')
->inRandomOrder()
->first();
echo $user->first_name . ' ' . $user->last_name;
Hope this helps!
Upvotes: 1