I query the list of users as below:
$users = \App\User::selectRaw('id, "user_name"')->paginate(2);
which returns:
{
current_page: 1,
data: [
{
id: 2,
user_name: "user_name"
},
{
id: 3,
user_name: "user_name"
}
],
first_page_url: "http://localhost:8000/users?page=1",
from: 1,
last_page: 2,
last_page_url: "http://localhost:8000/users?page=2",
next_page_url: "http://localhost:8000/users?page=2",
path: "http://localhost:8000/users",
per_page: 2,
prev_page_url: null,
to: 2,
total: 3
}
I need to just store the value of users which stored inside data:
to a variable, how could I achieve it?
data:[]
access it separately and store it inside another variable. – Minority$test = $users['data']
– Stitch$users->data
and it throws error:Undefined property: Illuminate\Pagination\LengthAwarePaginator::$data
– Minoritypaginate
? you may$users = \App\User::selectRaw('id, "user_name"')->take(2);
– Stitch