【发布时间】:2018-01-16 23:00:15
【问题描述】:
根据文档,一切都应该正常工作......但是......它没有。我做错了什么还是实际上是一个错误?
相关模型:邀请
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');
}
}
在路线(web.php)我有:
Route::get('/register/{invitation}', 'Auth\RegisterController@showInvitation')->name('invitation.show');
并且在view和mail中的view中使用了相同的功能:
{{ route('invitation.show', ['invitation' => $invitation]) }}
在常规网络视图中,路由会正确生成:
http://host.local/register/PCBIIHW12e6GBSaK
在电子邮件中显示的路线:
http://host.local/register/0
路线中还有这个小sn-p:
Route::get('/test/{id}', function($id) {
$i = \App\Invitation::find($id);
dump( $i->invite_code );
});
转储(加载适当的模型)... dum-dum-dum - 0;
迁移(以防万一)
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');
});
任何人都可以解释到底发生了什么?
【问题讨论】:
-
给我看控制器
-
public function showInvitation(Invitation $invitation) { if ($invitation->expires_at $邀请]); } $invitation->load('user'); return view('auth.invitation.index', ['invitation' => $invitation]); }
-
在邮件视图中检查
$invitation的值
标签: php laravel laravel-5 routes laravel-5.5