samedi 1 juillet 2017

How to make url with slug in Laravel 5.4?

right now I am trying to do a Laravel url with slug. I have my main page where I show all categories:

<div class="panel-body">
      @foreach($categories as $category)
            <p><a href=""></a></p>
      @endforeach
</div>

And now I want to go to a certain category page. I created routes:

Route::get('/test', 'test@index')->name('fuel_accounting');
Route::get('/test/{slug}', 'Test@element');

And function in controller:

public function element($slug)
{
    $category = DB::table('test')
        ->select('slug')
        ->where('slug', '=', $slug)
        ->first();

    return view('pages.test')->with('category', $category);
}

And when I am trying to reach page (for example: http://ift.tt/2uwmRXD) it does not work. Page could not be found. Can someone explain me how to do that?




Aucun commentaire:

Enregistrer un commentaire