db seeder文件中的Laravel Route函数 [英] Laravel route function in db seeder file

查看:93
本文介绍了db seeder文件中的Laravel Route函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从命名路由获取url.当我在头文件中调用该方法时

<a href="{{route('cmsPage', 'thematic_areas')}}" class="dropdown-toggle" data-hover="dropdown">Thematic Areas<b class="caret"></b></a>

结果正确

http://hassaan.discover.local/page/thematic_areas

在db种子文件中调用同一方法时

AdminNavBar::create(array('name'=>'Thematic Area', 'link'=>route('cmsPage', 'thematic_areas'), 'parent_id'=>'0'));

结果不正确. (从php artisan运行种子后存储在db中的URL)

http://localhost/page/thematic_areas

我无法弄清楚为什么基URL的播种会变得不同

解决方案

看起来工匠正在为您的Web服务器选择其他环境配置. config/app.php中的url设置默认为http://localhost.

调用artisan db:seed时,

尝试使用--env=local(或任何正确的环境)标志.

I am trying to get url from a named route. When I call the method in header file

<a href="{{route('cmsPage', 'thematic_areas')}}" class="dropdown-toggle" data-hover="dropdown">Thematic Areas<b class="caret"></b></a>

The result is correct

http://hassaan.discover.local/page/thematic_areas

Whereas when the same method is called in db seeder file

AdminNavBar::create(array('name'=>'Thematic Area', 'link'=>route('cmsPage', 'thematic_areas'), 'parent_id'=>'0'));

The result is incorrect. (URL which is stored in db after running seed from php artisan)

http://localhost/page/thematic_areas

I cannot figure out why the base URL becomes different in seeding

解决方案

Looks like artisan is picking up a different environment config to your webserver. The url setting in config/app.php defaults to http://localhost.

try using the --env=local (or whatever the correct environment is) flag when you call artisan db:seed

这篇关于db seeder文件中的Laravel Route函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆