Reputation: 69
When a I click to a link, I want to pass $row->id to another view.
Here it is my link:
foreach($artisti as $row) {
$artists .= '
<a href="{{ url(\'result/artista/\'.$row->id.\'/\') }}" class="dropdown-item">'.$row->nome.'</a>
';
}
Here it is my controller:
public function result($id)
{
return view('result')->with('id', $id);
}
Here it is my web.php:
Route::get('/result/artista/{id}', 'LiveSearch@result')->name('artista');
Here it is the view I want to send the variable:
@extends('layouts.dashboard')
@section('content')
<h1>{{$id}}</h1>
@endsection
Upvotes: 1
Views: 516
Reputation: 1769
Make your link in this way. Check that and let me know
foreach($artisti as $row) {
$artists .= '
<a href="'.{{ route('artista',$row->id) }}.'" class="dropdown-item">'.$row->nome.'</a>
';
}
If above doesn't work then do this way
foreach($artisti as $row) {
$artists .= '
<a href="'.route('artista', ['id' => $row->id]).'" class="dropdown-item">'.$row->nome.'</a>
';
}
Upvotes: 1
Reputation: 913
try this in your blade
{{ url('result/artista/'.$row->id) }}
Route::get('/result/artista/{id}', 'LiveSearch@result')
Edit1: For your named route only
route('artista', ['id' => $row->id]);
in controller : try print_r($id)
Upvotes: 1