Cviebrock \ EloquentSluggable包不起作用

时间:2018-10-13 18:14:49

标签: php laravel laravel-routing slug

我正在使用Laravel 5.7。*和sluggable ^4.6

在模型中:

namespace App;

use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;

class Subscriber extends Model
{   
    use Sluggable;

    public function sluggable()
    {
        return [
            'slug' => [
                'source' => 'value'
            ]
        ];
    }
}

和表格:

enter image description here

和web.php(我测试了所有这些)

Route::get('/subscribers/{subscriberSlug}',  'Mails\SubscriberController@verified_mobile')->name('subscriber.verified_mobile');

Route::get('/subscribers/{slug}',  'Mails\SubscriberController@verified_mobile')->name('subscriber.verified_mobile');

Route::get('/subscribers/{subscriber}',  'Mails\SubscriberController@verified_mobile')->name('subscriber.verified_mobile');

并在控制器中:

public function verified_mobile(Subscriber $subscriber)
{
    dd($subscriber);
}

并使用以下URL进行调用:

  

http://localhost/subscribers/aaa

但是它返回了一个空对象,像这样:

enter image description here

对于所有其他类似的URL,它也会返回如下相同的结果:

  

http://localhost/subscribers/aaaaaa

     

http://localhost/subscribers/asdasdaf

我怎么了?

0 个答案:

没有答案