Reputation: 1
I have a function in Laravel which running this code below
$data = AnggotaModel::where([
['status_nikah','Menikah'],
['jk','Pria']
])->get();
below is the screenshoot captured from dd($data);
What I want is to catch the id so I use this code
$id = $data[id];
as the result, it ends up with an Error
What should I do to fix this error??
Upvotes: 0
Views: 73
Reputation: 758
The get()
method gives you a collection of items. Get the first element then use $data[id]
.
Here you should change it to:
$id = $data->first()[id];
// Or in a better way:
$id = $data->first()->id;
Upvotes: 3