<commit_before><?php

namespace App;

use Mail;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Election extends Model
{
    use SoftDeletes;

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

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

    public function creator()
    {
        return $this->belongsTo('App\User', 'creator_id');
    }

    public function electors()
    {
        return $this->belongsToMany('App\User', 'electors');
    }

    public function candidates()
    {
        return $this->hasMany('App\Candidate');
    }

    public function invites()
    {
        return $this->belongsToMany('App\Invite', 'electors')->whereNull('accepted_at');
    }

    public function send_invite_email($email)
    {
        try {
            Mail::raw('Text to e-mail', function ($message) use ($email) {
                $name = 'Elector';
                $message->to($email, $name)->subject('Pivot Libre Election Invitation');
            });
        } catch(\Exception $e) {
            return $e->getMessage();
        }
        return null;
    }

    public function invite($email)
    {
        $invite = $this->invites()->where(['email' => $email])->first();
        $mail_error = null;

        if (empty($invite))
        {
            $invite = new Invite();
            $invite->code = bin2hex(random_bytes(4));
            $invite->email = $email;
            $invite->save();

            $elector = new Elector();
            $elector->election()->associate($this);
            $elector->invite()->associate($invite);
            $elector->save();
        }

        $mail_error = $this->send_invite_email($email);

        $result = $invite->toArray();
        $result['mail_error'] = $mail_error;
        return $result;
    }
}
<commit_msg>send (slightly) better invite message<commit_after><?php

namespace App;

use Mail;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Election extends Model
{
    use SoftDeletes;

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

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

    public function creator()
    {
        return $this->belongsTo('App\User', 'creator_id');
    }

    public function electors()
    {
        return $this->belongsToMany('App\User', 'electors');
    }

    public function candidates()
    {
        return $this->hasMany('App\Candidate');
    }

    public function invites()
    {
        return $this->belongsToMany('App\Invite', 'electors')->whereNull('accepted_at');
    }

    public function send_invite_email($email, $code)
    {
        $msg = 'Your Pivot Libre code is '.$code;
        
        try {
            Mail::raw($msg, function ($message) use ($email) {
                $name = 'Elector';
                $message->to($email, $name)->subject('Pivot Libre Election Invitation');
            });
        } catch(\Exception $e) {
            return $e->getMessage();
        }
        return null;
    }

    public function invite($email)
    {
        $invite = $this->invites()->where(['email' => $email])->first();
        $mail_error = null;

        if (empty($invite))
        {
            $invite = new Invite();
            $invite->code = bin2hex(random_bytes(4));
            $invite->email = $email;
            $invite->save();

            $elector = new Elector();
            $elector->election()->associate($this);
            $elector->invite()->associate($invite);
            $elector->save();

            $mail_error = $this->send_invite_email($email, $invite->code);
        }

        $result = $invite->toArray();
        $result['mail_error'] = $mail_error;
        return $result;
    }
}

{'fraction_non_alphanumeric': 0.15132066156504567, 'fraction_numerical': 0.0009874105159219946, 'mean_word_length': 2.039759939984996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 48, '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': '6225571', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1203, 'n_words': 247}