32 lines
811 B
PHP
32 lines
811 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class InstantGagnant extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function magasin()
|
|
{
|
|
return $this->belongsTo(Magasin::class);
|
|
}
|
|
|
|
public function participation()
|
|
{
|
|
// La première participation du user de cet InstantGagnant avec le magasin
|
|
// après la date de cet Instant gagnant
|
|
// cela sera forcément la participation qui aura fait gagner le user
|
|
return Participation::where('user_id', $this->user_id)
|
|
->where('magasin_id', $this->magasin_id)
|
|
->where('created_at', '>=', $this->date)
|
|
->first();
|
|
}
|
|
}
|