A typo is fixed, which, as I thought, should disable the entire resource of the route, but disable only the URI using the template

A simple application for Google Chrome, the addition of tag features and all routes still work. Index and page creation is rendering, new tags are kept in order, but when I try to get to the edit page (/ admin / tag / 1 / edit), Laravel throws

NotFoundHttpException in RouteCollection.php line 161

I check my route: the list and it looks good, Firebug just gives a basic 404 not found in the GET app.dev/admin/tag/1/edit. In the end, I noticed a trailing slash in the tag:

$router->group([
    'namespace' => 'Admin',
    'middleware' => 'auth',
    ], function () {
    resource('admin/post', 'PostController');
    resource('admin/tag/', 'TagController');
});

changed it to

    resource('admin/tag', 'TagController');

and now the edit pages look just fine.

, URI {$ id} (, , , ). . URI , ?

+4
1

prefix :

$router->group([
  'prefix' => 'admin',  // <= prefix
  'namespace' => 'Admin',
  'middleware' => 'auth',      
  ], function () {
  resource('post', 'PostController'); // <= changes , eq. admin/post
  resource('tag', 'TagController');  // <= changes , eq. admin/tag
});

" ". , . , , .

, \vendor\laravel\framework\src\Illuminate\Routing\ResourceRegistrar.php, :

   protected $resourceDefaults = ['index', 'create', 'store', 'show', 'edit', 'update', 'destroy'];

'register':

    public function register($name, $controller, array $options = [])
{
    // If the resource name contains a slash, we will assume the developer wishes to
    // register these resource routes with a prefix so we will set that up out of
    // the box so they don't have to mess with it. Otherwise, we will continue.
    if (Str::contains($name, '/')) {
        $this->prefixedResource($name, $controller, $options);
        return;
    }

    // We need to extract the base resource from the resource name. Nested resources
    // are supported in the framework, but we need to know what name to use for a
    // place-holder on the route wildcards, which should be the base resources.
    $base = $this->getResourceWildcard(last(explode('.', $name)));

    $defaults = $this->resourceDefaults;

    foreach ($this->getResourceMethods($defaults, $options) as $m) {
        $this->{'addResource'.ucfirst($m)}($name, $base, $controller, $options);
    }
}

admin/tag/ :

if (Str::contains($name, '/')) { /*...*/ }

( ), , 99% - explode/implode ( " " - . , ) = > , .. ( 404).

+2

Source: https://habr.com/ru/post/1612520/


All Articles