<commit_before><?php

namespace App;

use App\Casts\EncryptedString;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Participant extends Model
{
    use Notifiable;
    use HashId {
        resolveRouteBinding as resolveParticipant;
    }

    protected static $hashConnection = 'santa';

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'name' => EncryptedString::class,
        'email' => EncryptedString::class,
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name', 'email', 'draw_id', 'target_id', 'mail_id'];

    // Fake property
    public $exclusions;

    public function draw()
    {
        return $this->belongsTo(Draw::class);
    }

    public function target()
    {
        return $this->hasOne(self::class, 'target_id');
    }

    public function santa()
    {
        return $this->belongsTo(self::class, 'target_id');
    }

    public function dearSanta()
    {
        return $this->hasMany(DearSanta::class, 'sender_id')->with('mail');
    }

    public function mail()
    {
        return $this->belongsTo(Mail::class, 'mail_id');
    }

    public function getFromDearSantaUrl($url)
    {
        $route = app('router')
            ->getRoutes()
            ->getByName('dearsanta');

        $request = app('request')
            ->create($this->argument('url'));

        $hash = $route->bind($request)->santa;

        return static::findByHashOrFail($hash);
    }

    /**
     * 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)
    {
        $participant = $this->resolveParticipant($value);

        return $participant->load(['dearsanta']);
    }<commit_msg>Add check on dearsanta page for expired draw<commit_after><?php

namespace App;

use App\Casts\EncryptedString;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Participant extends Model
{
    use Notifiable;
    use HashId {
        resolveRouteBinding as resolveParticipant;
    }

    protected static $hashConnection = 'santa';

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'name' => EncryptedString::class,
        'email' => EncryptedString::class,
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name', 'email', 'draw_id', 'target_id', 'mail_id'];

    // Fake property
    public $exclusions;

    public function draw()
    {
        return $this->belongsTo(Draw::class);
    }

    public function target()
    {
        return $this->hasOne(self::class, 'target_id');
    }

    public function santa()
    {
        return $this->belongsTo(self::class, 'target_id');
    }

    public function dearSanta()
    {
        return $this->hasMany(DearSanta::class, 'sender_id')->with('mail');
    }

    public function mail()
    {
        return $this->belongsTo(Mail::class, 'mail_id');
    }

    public function getFromDearSantaUrl($url)
    {
        $route = app('router')
            ->getRoutes()
            ->getByName('dearsanta');

        $request = app('request')
            ->create($this->argument('url'));

        $hash = $route->bind($request)->santa;

        return static::findByHashOrFail($hash);
    }

    /**
     * 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)
    {
        $participant = $this->resolveParticipant($value);

        abort_if($participant->draw->expired, 404);

        return $participant->load(['dearsanta']);
    }
{'fraction_non_alphanumeric': 0.13783649052841476, 'fraction_numerical': 0.0007477567298105683, 'mean_word_length': 2.409515717926933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '613872', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1197, 'n_words': 257}