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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀