I have a draw system on my site. There are 2 draws in the database now, but for some reason, only the last created draw is displayed on the draw page. My code is:
public function raffling()
{
parent::setTitle('Items raffling | ');
$green_ticket = \DB::table('users')->where('id', $this->user->id)->value('green_ticket');
$kolvo=\DB::table('giveaway_items')->where('status',0)->orderBy('id', 'desc')->count();
$giveaway = Giveaway::orderBy('id', 'desc')->first();
$giveaway_users = \DB::table('giveaway_users')
->where('giveaway_id', $giveaway->id)
->join('users', 'giveaway_users.user_id', '=', 'users.id')
->get();
$giveAway = Giveaway::where('winner_id', '!=', 'NULL')->orderBy('created_at', 'DESC')->first();
$user = User::find($giveAway->winner_id);
$username = $user->username;
$userava = $user->avatar;
$usersteamid = $user->steamid64;
return view('pages.raffling', compact('kolvo', 'giveaway', 'giveaway_users', 'giveAway', 'user', 'username',
'userava', 'usersteamid', 'green_ticket'));
}
I tried make changes at $giveaway = Giveaway::orderBy('id', 'desc')->first();
and instead of first()
use take(2)
, but i received error Undefined property: Illuminate\Database\Eloquent\Builder::$winner_id
. And the same error appears if I add take(2)
to the line $giveAway = Giveaway::where('winner_id', '!=', 'NULL')->orderBy('created_at', 'DESC')->first();
instead of first()
.
Where is my problem, how i can fix this error?