在我的Laravel应用程序中,当我试图用他的个人资料页面链接在网站上的人的用户名时,代码是:
<div class="media-body"><a href="@{{ post.user.profileUrl }}">@{{ post.user.name }}</a>
它给出了错误:
对不起,找不到您要找的页面。 1/1 NotFoundHttpException在RouteCollection.php行161:
但是,当我试图打印@{{ post.user.profileUrl }}
时,它给出了正确的地址,也是在json响应中,它给出了正确的地址,而去地址也就是到达特定的位置。
所以,我不认为这是post.user.profileUrl的一些问题,因为它似乎很好,它似乎是一些问题在使用它与href,在Google中的错误地址是:
http://localhost:8000/%7B%7B%20post.user.profileUrl%20%7D%7D
地址应该是
http://localhost:8000/users/2,其中2引用用户的id,我通过Vue.js传递给用户。
发布于 2016-12-16 06:35:57
问题是@{{ post.user.profileUrl }}
不是解析。%7B%7B%20post.user.profileUrl%20%7D%7D
是{{ post.user.profileUrl }}
的ASCII表示
检查代码是否在.blade.php
文件中。如果是的话,如果您使用的是JS模板引擎,则应该查看它。
https://laravel.com/docs/5.3/blade#blade-and-javascript-frameworks
@符号将被Blade删除;但是,{{ name }表达式将不受刀片引擎的影响,允许由您的JavaScript框架来呈现它。
发布于 2016-12-16 06:37:12
我认为你的观点中有一个$post
模型。当您在模型Post
和User
之间建立关系时,您可以通过以下方法链接到它们:
<a href="{{ url('/@'.$post->user->profileUrl) }}">@{{ $post->user->name }}</a>
这将将用户profileUrl
转换为有效的链接。但为此,你必须在模型中建立关系。
职位模式:
public function user() {
return $this->hasMany('App\Users', 'id', 'user_id');
//first parameter is the Model class
//send is the id of the user table
//thirth is the user_id in the post table
}
在用户模型中:
public function posts() {
return $this->hasMany('App\Posts', 'user_id', 'id');
}
希望这行得通!
发布于 2016-12-16 06:49:56
试试这个..。这对你绝对有用。
@verbatim
<div class="media-body">
<a href="{{ post.user.profileUrl }}">
{{ post.user.name }}
</a>
</div>
@endverbatim
https://stackoverflow.com/questions/41178504
复制相似问题