I want a single row of player through his playerNo field which is later added and updated.
I am doing this.
$player = Account::where('playerNo', 99)->get();
Result I am getting is many objects of players that only has player object with playerNo, which I do not want because for that I have to use iteration.
foreach($players as $player)
$player->name = "Sadan"
2
Answers
To get only a single Model returned use
first()
.eg
However if you were getting multiple models by using get() then you have multiple models that match with a playerNo of 99 which seems odd.
To get single row in Laravel you can use
first()
in model or controller below;$player = Account::where(‘playerNo’, 99)->first();
To get data in blade below::
Name : {{ $player->name }}