i have a grid in which all users are shown . the grid is created and shown by ajax , it has 3 buttons . add , edit , remove . i can add and delete , but since in the update.blade.php i have the user image ( which is shown by a route and controller like : <img src="{{ route('userimage',['id' => $pass_the_id ])}}"/>
, the problem now is how do i pass variable like $pass_the_id
that i'm about to use in the view blade ?` , this is the code that brings up the modal ( when edit button which is right in front of user name and id is clicked . i can get user name , family and so on and show it in the modal . but how do i pass the $id to the image route that i mentioned above ?
$('body').delegate('#student-info #edit','click',function (e) {
var id = $(this).data('id');
$.get("{{ URL::to('student/edit') }}",{id:id},function (data) {
$('#frm-update').find('#id').val(data.id);
$('#frm-update').find('#name').val(data.name);
$('#frm-update').find('#family').val(data.family);
$('#frm-update').find('#username').val(data.username);
$('#frm-update').find('#birth_date').val(data.birth_date);
$('#frm-update').find('#phone').val(data.cell_phone);
$('#frm-update').find('#email').val(data.email);
$('#frm-update').find('#gender').val(data.gender);
$('#student-update').modal('show');
})
})
here is the laravel Controller function that is called on URL::to('student/edit')
wich i have mentioned in the above $.get
code :
public function edit(Request $request) {
if($request->ajax()) {
$contact = User::find($request->id);
return response($contact);
}
}
the responsibility of above controller function which is called during $.get
is to get the information based on the id that i have passed . ( my grid already shows each user id in the the grid table i've created . but i don't know how to pass it to the src="{{ route('userimage',['id' => $pass_the_id ])}}"
here is what userimage route is doing : bellow is the route :
Route::get('userimage/{id}','ImageController@showimage')->name('userimage');
and this is its code :
public function showimage($id) {
if(UserImages::selectuserimage($id) !== null) {
$imageData = UserImages::selectuserimage($id);
$info = $info = base64_decode($imageData);
$img = Imgs::make($info);
$img->encode('jpg',80);
return $img;
}
else return public_path('images/Atehran.jpg');
}