在Laravel 5

时间:2015-11-12 16:31:23

标签: laravel-5

我有一些代码:

routes.php文件

Route::get('/countries/{country1}', [
    'uses' => 'CountryController@editCountr',
    'as' => 'edit1'
    ]);
Route::get('/countries', ['uses' => 'CountryController@getAll', 'as' => 'countries']);

CountryController.php

public function editCountr($country1){
    $countries = Country::where('country','=', $country1);
    return view('countryedit')->with('country1', $countries);
}

countries.blade.php

<a href="{{route('edit1')}}">{{$country->country}}</a>

所以,我有一个问题: 我在countries.blade.php中的链接看起来像http://localhost:8000/countries/%7Bcountry1%7D

请帮帮我吗?

1 个答案:

答案 0 :(得分:1)

首先,您必须在控制器中获取一个对象:

public function editCountr($country1){
    $countries = Country::where('country','=', $country1)->first();
    return view('countryedit')->with('country1', $countries);
}

您必须为路线功能提供属性:

   <a href="{{route('edit1', ['country1' => $country1->country])}}">{{$country1->country}}</a>