问题
I'm new in Laravel 5 and I need some help since I can't solve my simple problem.
I have a list of data on http://sample.com/partners and if I will click the link of the data I like it to redirect it to
http://sample.com/partners/users/77 and it will display the information about the user with the id 77.
I can't provide my route and controller but here is my partners.blade.php
@foreach ($data as $partners)
<tr bgcolor="#FF9999">
<td><a href="{{ $partners->partner_id }}"> {{ $partners->partner_id }} </a></td>
<td>{{$partners->name}}</td>
<td>{{$partners->address}}</td>
<td>{{$partners->tel_line_no}}</td>
</tr>
@endforeach
回答1:
Use the url or route helper functions in your <a>
tag.
<a href="{{ url('partners/users', [$partners->partner_id]) }}">
{{ $partners->partner_id }}
</a>
This assumes you have something like this in your routes.php
:
Route::model('partner', App\Partner::class);
Route::get('/partners/users/{partner}', function(App\Partner $partner) {
view('show-partner', ['partner' => $partner]);
});
回答2:
First you need this on your Routes.php:
Route::get('partnets/users/{users}','YourController@yourMethod');
Add this method to 'YourController' Controller:
Public function yourMethod($user)
{
Your code... $user will have the ID
}
Your view:
<td><a href="{{ url('partners/users',[$partners->partner_id] }}"> {{ $partners->partner_id }} </a></td>
or
<td><a href="{{ action('YourController@yourMethod',['users' => $partners->partner_id] }}"> {{ $partners->partner_id }} </a></td>
来源:https://stackoverflow.com/questions/31622218/laravel-passing-the-data-to-route