can you dd your return $html?
Sep 14, 2019
18
Level 1
Laravel, cant fill empty table
I am trying to fill my empty table with data based on selected value using drop-down although my code is running and does not show any error my table remains empty.
create.blade.php
<select name="course_id" id="course" class="form-control">
@foreach($courses as $id => $course)
<option value="{{ $id }}" {{ (isset($applicant) && $applicant->course ? $applicant->course->id : old('course_id')) == $id ? 'selected' : '' }}>
{{ $course }}
</option>
@endforeach
</select>
Script
<script>
$(function(){
$('#course').change(function() {
$.ajax({
url: 'applicants/create/{id}',
type: 'GET',
data: { id: $(this).val() },
success: function(response)
{
$('#subjectData tbody').html(response);
}
});
});
});
</script>
Controller
public function getSubject($id)
{
$result = Subject::all()->where('course_ID', $id);
foreach($result as $row)
{
$html =
'<tr>
<td>' . $row->subj_code . '</td>' .
'<td>' . $row->subj_code . '</td>' .
'</tr>';
}
return $html;
}
Route
Route::group(['prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'Admin', 'middleware' => ['auth']], function () {
Route::get('applicants/create/{id}', 'ApplicantController@getSubject');
Route::resource('applicants', 'ApplicantController');
});
Please or to participate in this conversation.