首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >路线[product.store]未用laravel确定

路线[product.store]未用laravel确定
EN

Stack Overflow用户
提问于 2019-10-23 15:39:42
回答 3查看 3.6K关注 0票数 0

在此之前,我只是有卖家可以创造新的产品,它的功能很好,没有错误。

所以现在,我增加了卖家可以创建新的类别,它的功能,但对于卖方创造新产品,而不是功能。

它显示路由product.store未定义。我怎么才能修好它?

这是在web.php里

代码语言:javascript
运行
复制
Route::get('/index', 'ProductController@index');
Route::get('/create', 'ProductController@create'); 
Route::post('','ProductController@store')->name('product.store');  
Route::get('/category/index', 'CategoryController@index');
Route::get('/category/create', 'CategoryController@create');
Route::post('','CategoryController@store')->name('category.store');

当我在//post::post(‘)上评论时,'CategoryController@store')->name('category.store');seller可以创建它的新产品,但卖方不能创建新的类别

这是product/create.blde.php

代码语言:javascript
运行
复制
<div class="container">
    <div class="row">
        @include('admin.includes.sidebar_admin')
         <div class="col-md-9">
              <div class="panel panel-primary">
      <div class="panel-heading">Create products</div>
      <div class="panel-body">


       <form action="{{route('product.store')}}" method="post" enctype="multipart/form-data">
        {{csrf_field()}}
         @csrf

这是类别/create.blde.php

代码语言:javascript
运行
复制
<div class="container">
    <div class="row">
        @include('admin.includes.sidebar_admin')
         <div class="col-md-9">
              <div class="panel panel-primary">
      <div class="panel-heading">Create New Category</div>
      <div class="panel-body">


       <form action="{{route('category.store')}}" method="post">
        {{csrf_field()}}
         @csrf
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-10-23 15:43:11

路由的命名是可以的,但是您必须提供一个端点,因为这是实际使用的。您不能投递到同一个端点并期望得到两个不同的结果。

所以这个:

代码语言:javascript
运行
复制
Route::post('','ProductController@store')->name('product.store');  

取而代之的可能是:

代码语言:javascript
运行
复制
Route::post('/products','ProductController@store')->name('product.store');  

这是:

代码语言:javascript
运行
复制
Route::post('','CategoryController@store')->name('category.store');

可以是:

代码语言:javascript
运行
复制
Route::post('/categories','CategoryController@store')->name('category.store');
票数 0
EN

Stack Overflow用户

发布于 2019-10-23 15:44:16

在您的web.php中,有两个重叠的路由。

代码语言:javascript
运行
复制
Route::get('/index', 'ProductController@index');
Route::get('/create', 'ProductController@create'); 
Route::post('','ProductController@store')->name('product.store');  //<----first one
Route::get('/category/index', 'CategoryController@index');
Route::get('/category/create', 'CategoryController@create');
Route::post('','CategoryController@store')->name('category.store'); //<----second one

将第二条路径更改为其他方式,如:

代码语言:javascript
运行
复制
Route::post('/category','CategoryController@store')->name('category.store');
票数 1
EN

Stack Overflow用户

发布于 2019-10-23 16:13:53

问题在于如何在web.php文件中声明路由名称。您正在用类别存储路由覆盖您的产品存储路由。

代码语言:javascript
运行
复制
Route::post('','ProductController@store')->name('product.store');  
Route::post('','CategoryController@store')->name('category.store'); 

有一段时间,您可能会认为他们的路线名称是不同的,所以他们不工作。不工作背后的一点是,路线名称提供了一些特殊的优势。假设您希望将路线更改为“产品/创建”之类的内容。然后你必须在你的项目中全部改变它们。如果他们使用了5次,你必须更换5次,如果50次或更多次,我希望你能猜出有多痛苦。为了从中解脱,路线的名字在这里。在这里,您可以给出一个路由的名称,并调用/引用他们的名字。因此,在将来,如果您将路径更改到其他东西,则无需费心更改引用,因为名称仍将是相同的。但是请注意,路由名称路由不能引用或指向相同的http谓词。在这里,您违反了规则,尽管您的路由名称不同,但是您使用相同的http谓词(POST)指向相同的路由。这就是为什么它用最后一个Route::post('','ProductController@store')->name('product.store');覆盖前一个Route::post('','CategoryController@store')->name('category.store');的原因。因此,对于product.store这个路线名称,Laravel是不知道的。

其他一些小更正:默认情况下,索引文件/方法会被触发。所以你可能要换掉它们

代码语言:javascript
运行
复制
//Route::get('/', 'ProductController@index')
Route::get('/index', 'ProductController@index');  
//Route::get('/category', 'CategoryController@index')
Route::get('/category/index', 'CategoryController@index');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58526528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档