douan4347 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

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-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

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

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换