mardi 16 janvier 2018

Laravel 5.5 named route with parameters in mailables

According to documentation, everything should work fine... However.. it doesn't. Am I doing something wrong or is it actually a bug?

Relevant model: Invitation

class Invitation extends Model
{
    protected $primaryKey = 'invite_code';

    protected $fillable = ['invite_code', 'creator_id', 'expires_at'];
    protected $dates = ['created_at', 'updated_at', 'expires_at'];

    public function getRouteKey()
    {
        return $this->attributes['invite_code'];
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

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

In routes (web.php) I have:

Route::get('/register/{invitation}', 'Auth\RegisterController@showInvitation')->name('invitation.show');

And the same functions are used in view and a view in mail:

In the regular web view the route generates properly:

http://ift.tt/2mC2C8L

In the email the route shows:

http://ift.tt/2DjdC5l

Also this little snippet in routes :

Route::get('/test/{id}', function($id) {
    $i = \App\Invitation::find($id);
    dump( $i->invite_code );
});

dumps out (with a proper model loaded)... dum-dum-dum - 0;

Migration (just in case)

Schema::create('invitations', function (Blueprint $table) {
    $table->string('invite_code')->primary();
    $table->integer('creator_id');
    $table->integer('user_id');
    $table->timestamps();
    $table->dateTime('expires_at');
});

Anyone can actually explain what's going on?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mC2CFN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire