A
A
ashfedor2020-08-24 20:27:10
Laravel
ashfedor, 2020-08-24 20:27:10

How to fix error in Laravel route?

Good day.
I am writing a small blog on Laravel and literally stalled on the frontend route.
It is necessary that the address contains both the slug of the category and the entry
itself, the route itself is like this

Route::resource('blog', 'PostController')
                ->only('index')
                ->names('blog');
            Route::get('{category}/{slug}', '[email protected]')
                ->name('blog.show');


in the controller while a stub for the method

public function show( $category, $slug)
    {
        dd(__METHOD__);
    }
</code

  в вьюхе я вывожу все посты @forelse? вобщем  как обычно
 и все работает test.loc/blog
но как только прописываю маршрут на полную новость

<code lang="php">
 <a class="btn btn-outline-primary" href="{{route('blog.show',['category' => $item->category->slug, 'slug'=> $item->slug ] )}}" role="button">Читать далее»</a>
</code>

 сразу лезет ошибка о том что не переданны данные в маршрут
Missing required parameters for [Route: blog.show] [URI: {category}/{slug}]. (View: G:\OSPanel\domains\test.loc\resources\views\site\front\blog\main.blade.php)

Что- то в ступор влез и не могу понять, вроде все просто но...!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton R., 2020-08-24
@ashfedor

Well, look which of these two methods is drizzling:
$item->category->slug or $item->slug, var_dump and you will see them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question