D
D
den-masonov2017-04-20 15:26:21
Laravel
den-masonov, 2017-04-20 15:26:21

I display the resource route '/' in the blade, but when I switch to dw.app/2, it gives 404. If the route is '/list', for example, then everything works. How to fix?

Tried both url(), and action(), and route().
This is in blade:

<a href="{{ url('/', [$article->id]) }}">{{ $article->title }}</a>

These are the routes:
Route::resource('/', 'ArticleController');

Route::get('/welcome', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', '[email protected]');

And ArticleController:
public function index()
    {
        $articles = Article::where('published', 1)->get();

        return view('list', ['articles' => $articles]);
    }

    public function show($id)
    {
        $article = Article::with('comments')->find($id);

        return view('article', ['article' => $article]);
    }

When following a link like dw.app/2, it throws NotFoundHttpException in RouteCollection.php line 179:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pLavrenov, 2017-04-20
@den-masonov

a01d62d4ba4f4eb9aaecb277c6aa8f15.png
Here are all the standard resource routes. The resource must have a name.
Should be corrected like this:

Route::resource('article', 'ArticleController');
route('article.show', ['id'=>$id]);

And to make article.index the main page, you can add:
1) To redirect to the article section
Route::get('/', function () {
        return redirect()->route('article.index');
});

2) So it will open at the root
For the link "/2" to work, you need the following route:
Route::get('/{id}', ['uses' => '[email protected]']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question