在laravel 5.3中建立链接的正确方法 [英] Right way to build a link in laravel 5.3

查看:75
本文介绍了在laravel 5.3中建立链接的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Laravel 5.3用视图页面(刀片)构建动态链接.

Im trying to build a dynamic link with a view page (blade) with Laravel 5.3.

我的方法是:

<a href=" {{ URL::to('articles') }}/{{ $article->id}}/edit">Edit></a>  

将会输出正确的URL以及我的基本URL和其他一些信息:http://mydomain/articles/23/edit
其中"23"是我的文章的ID.

that will output the right url with my base url and some other slug: http://mydomain/articles/23/edit
Where "23" is my article's id.

这行得通,但是我想知道是否有一种更清洁的方法?

This works but I wonder if there is a cleaner way to do that?

非常感谢

推荐答案

您可以使用为此

You can use named routes for this

// Your route file
URL::get('articles/{articleId}/edit', 'ArticlesController@edit')->name('articles.edit');

//Your view
<a href="{{ URL::route('articles.edit', $article->id) }}">Edit</a>

更清洁的IMO

这篇关于在laravel 5.3中建立链接的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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