dimanche 30 juillet 2017

Loading url with slug in laravel 5.4

I realize that there are similar questions but non of them is helped me so far. So I'm trying to make URL's to load with slug. In RouteServiceProvider I have added this

public function boot()
{
    //
    parent::boot();

    Route::bind('/', function($slug) {
        return Pages::where('slug', $slug)->first();
    });
}

In my routes this

Route::get('/{page}', [
    'uses' => 'HomeController@page',
    'as' => 'page'
]);

The button in the view

<a href=""></a>

And my model

class Pages extends Eloquent {

    protected $fillable = ['page_title', 'slug', 'page_body'];
    protected $table = 'pages';
    protected $primaryKey = 'page_id';

    public $timestamps = false;

}

When I click on the link to open the page the error is

NotFoundHttpException No query results for model [App\Pages].

I have added use App\Pages to files too.

I can't see what is wrong here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire