2017-11-23 04:59
浏览 67

路由未定义php laravel5.5

I got an error : Route [admin/news] not defined I try to use @component in my create.blade.php

In my Controller I declare variable

public $route = 'admin/news' ;

In web.php

Route::post('admin/news/create', 'Admin\NewsController@store');
Route::resource('admin/news', 'Admin\NewsController');

In my html this return right Url

<a class="btn btn-success" href="{{ asset($route.'/create') }}">add</a>

<a class="btn btn-success" href="{{ route('news.create') }}">add</a>

I check my route by using php artisan r:l

It has a news.create

I try to use other routes both of these work fine not sure what's wrong with my create route


the problem is in my create.blade.php I try to use @component by this

              ['id'=>'create','method'=> isset($edit) ? 'PUT' : 'POST' ,'action'=> isset($data->id) ? asset($route.'/'.$data->id) : route($route)]

图片转代码服务由CSDN问答提供 功能建议

我收到错误:路由[admin / news]未定义我尝试在create.blade中使用@component .php


  public $ route ='admin / news'; 
  <  / pre> 


  Route :: post('admin / news / create','Admin \ NewsController @ store');  
Route :: resource('admin / news','Admin \ NewsController'); 

在我的html中这个返回权利Url \ n

 &lt; a class =“btn btn-success”href =“{{asset($ route。'/ create')}}”&gt; add&lt; / a&gt; 
&lt; a class  =“btn btn-success”href =“{{route('news.create')}}”&gt; add&lt; / a&gt; 

我检查了我的 路线使用php artisan r:l

它有 news.create

我尝试使用其他路线 这些工作很好,不知道我的创建路线有什么问题

  route('news.edit',$ t-&gt; id)
route('news.destroy',  $ t-&gt; id)

问题出在我的脑后 ate.blade.php 我尝试使用@component

 ['id'=&gt;' 创建”, '方法'=&GT;  isset($ edit)?  'PUT':'POST','action'=&gt;  isset($ data-&gt; id)?  asset($ route。'/'。$ data-&gt; id):route($ route)] 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhuang2570 2017-11-23 05:41

    You have $route set to admin/news. You say you want to go to the create page. You then say that the route is named news.create. So use news.create as the name when referencing it with the helper. Set $route to news.create.

    You seem to want to use a URI and a route name. You have to decide which one you are going for.

    Laravel Docs - Routing - Named Routes

    Laravel Docs - Helpers - Url Helpers - route

    解决 无用
    打赏 举报

相关推荐 更多相似问题