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:
{{ route('invitation.show', ['invitation' => $invitation]) }}
In the regular web view the route generates properly:
http://host.local/register/PCBIIHW12e6GBSaK
In the email the route shows:
http://host.local/register/0
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?
It's interesting as it seems it's now working. I've changed the schema by renaming the field to token
instead of invite_code
... and... it's all working as intended... weird.
Solution - do not use double words as RouteNameKeys...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.