Verified Commit 18ad4a66 authored by Korko's avatar Korko
Browse files

Handle expiration date at resolution

parent 46c14e57
......@@ -10,7 +10,9 @@ use Illuminate\Database\Eloquent\Model;
class Draw extends Model
{
use HashId;
use HashId {
resolveRouteBinding as resolveDraw;
}
protected static $hashConnection = 'draw';
......@@ -62,4 +64,25 @@ class Draw extends Model
{
return $this->participants->first();
}
public function getExpiredAttribute()
{
return $this->expires_at->isPast() || $this->expires_at->isToday();
}
/**
* Retrieve the model for a bound value.
*
* @param mixed $value
* @param string|null $field
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function resolveRouteBinding($value, $field = null)
{
$draw = $this->resolveDraw($value);
abort_if($draw->expired, 404);
return $draw->load(['participants', 'participants.mail']);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment