douan4347 2017-11-22 20: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

route('news.edit',$t->id)
route('news.destroy',$t->id)

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

 @component('layouts.submitform',
              ['id'=>'create','method'=> isset($edit) ? 'PUT' : 'POST' ,'action'=> isset($data->id) ? asset($route.'/'.$data->id) : route($route)]
            )
  • 写回答

1条回答 默认 最新

  • douzhuang2570 2017-11-22 21: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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥100 二维码被拦截如何处理
  • ¥15 怎么解决LogIn.vue中多出来的div
  • ¥15 优博讯dt50巴枪怎么提取镜像
  • ¥30 在CodBlock上用c++语言运行
  • ¥15 求C6748 IIC EEPROM程序固化烧写算法
  • ¥50 关于#php#的问题,请各位专家解答!
  • ¥15 python 3.8.0版本,安装官方库ibm_db遇到问题,提示找不到ibm_db模块。如何解决?
  • ¥15 TMUXHS4412如何防止静电,
  • ¥30 Metashape软件中如何将建模后的图像中的植被与庄稼点云删除
  • ¥20 机械振动学课后习题求解答
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部