K
K
Kristina87872020-09-15 17:15:35
Laravel
Kristina8787, 2020-09-15 17:15:35

Why does laravel give me the error Missing required parameters for [Route: admin.articles.edit]?

Good day. I have routes:

Route::prefix('admin')->middleware('auth')->group(function() {

    //admin
    Route::get('/',['uses' => 'Admin\[email protected]','as' => 'adminIndex']);

    Route::resource('/articles','Admin\ArticlesController');

});

I think here no one needs to explain what is here and why, and so, the problem is that when on the page that the index method should issue, I write the route in the link:
@foreach($articles as $article)
                        <tr>
                            <td class="align-left">{{$article->id}}</td>
                            <td class="align-left">{!! Html::link(route('admin.articles.edit',['articles'=>$article->alias]),$article->title) !!}</td>
                            <td class="align-left">{{Str::limit($article->text,200)}}</td>
                            <td>
                                @if(isset($article->img->mini))
                                    {!! Html::image(asset(env('THEME')).'/images/articles/'.$article->img->mini) !!}
                                @endif
                            </td>


then I get an error that there is no such route at all, Route [admin.articles.edit] not defined,
if I change the route group to this:
Route::name('admin.')->prefix('admin')->middleware('auth')->group(function() {

those. I just add admin to the name. , then the route is located, but the error is already like this Missing required parameters for [Route: admin.articles.edit], but if I do it like a monkey, i.e. inside the group I write the following route:
Route::get('/articles/edit/{articles?}',['uses'=>'Admin\[email protected]','as'=>'admin.articles.edit']);

then everything works. And such a story with each CRUD route, and I need Route::resource to work as expected, help me find the error, I have already read and looked at this issue so much, nothing has come up yet, I’m sure the error is somehow simple, but I point it out I do not see

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2020-09-16
@Kristina8787

The prefix in the route group does not affect the name of the routes. name is only affected by name. The route should be like this Without any obscure links and constructions. In the controller, already get the necessary properties of the $article->tilte type. And you shouldn't call Env directly. This is done in configs based on existing Laravel examples.
route('articles.edit', $article)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question