laravel 5路由传递两个参数 [英] laravel 5 route passing two parameters

查看:99
本文介绍了laravel 5路由传递两个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这条路线

Route::get('/artist/{id}/{name}', 'HomeController@artist')->where(['id' => '[0-9]+', 'name' => '[a-z]+'])->name('artist');

这是我的链接

<a href="{{route('artist',$artist->id,$artist->name)}}">{{$artist->name}}</a>

这是HomeController上的artist方法

and this is the artist method on HomeController

public function artist($id, $name){ $artist = Artist::where('id', $id)->where('name', $name)->first();

    return view('front.artist', compact('artist'));
}

我不知道此显示错误.这是错误.所以请任何人帮我我在学习幼虫中间.

i donot know this display error. this is the error. so please any one help me with this. iam in the middle of learning laravel.

ErrorException in UrlGenerationException.php line 17:
Missing required parameters for [Route: artist] [URI: artist/{id}/{name}]. (View: C:\xampp\htdocs\laravel\resources\views\front\home.blade.php)

推荐答案

您必须将参数作为数组传递,请参见 https://laravel.com/docs/5.4/helpers#method-route

Yo must pass the parameters as array, see https://laravel.com/docs/5.4/helpers#method-route

route('artist',['id' => $artist->id, 'name' => $artist->name])

或者您可以使用

{!! link_to_route('artist', $artist->name, ['id' => $artist->id, 'name' => $artist->name]) !!}

这篇关于laravel 5路由传递两个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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