【问题标题】:Laravel 5.5 named route with parameters in mailablesLaravel 5.5 命名路由,在 mailables 中带有参数
【发布时间】: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


【解决方案1】:

这很有趣,因为它现在似乎正在工作。我已经通过将字段重命名为 token 而不是 invite_code 来更改架构......而且......一切都按预期工作......很奇怪。

解决方案 - 不要使用双字作为 RouteNameKeys...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-06
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 2018-08-31
    • 1970-01-01
    相关资源
    最近更新 更多