I have the following code in FreelancerControler:
public function search(Request $request)
{
if ($request->ajax()) {
$data = User::where('name','LIKE',$request->name.'%')->where('role','freelancer')->get();
$output = '';
if (count($data)>0) {
foreach ($data as $user) {
$output .= ' <div class="row freelancer p-1 m-1">
<div class="col-sm-3">
<img src="'.$user->avatar.'" height="100px" width="100px">
</div>
<div class="col-sm-9">
<h3><a href={{route("profile",["id"=>'.$user->id.'])}}>'.$user->name.'}}</a></h3>
<p>'.$user->profile->title.'</p>
<p>'.$user->profile->about.'</p>
</div>
</div>';
}
}else {
$output .= 'No Data Found';
}
return $output;
}
return view('autosearch');
}
My problem is in this line:
<h3><a href={{route("profile",["id"=>'.$user->id.'])}}>'.$user->name.'}}</a></h3>
its output is a broken links with this text: "3])}}>Karam}}"
, as the user_id is 3 and user_name is Karam.
2
Answers
Syntax Error:
you may use this one:
This will put the value instead of blade format to perform additional step in ajax to render.
You can use the route function in controller but using a concatenations
something like this