I'm trying to pass an array from Controller to Blade My Controller:
public function socaucuachuong($id){ $socaucuachuong = CauHoi::groupBy('chuong')->select('chuong', CauHoi::raw('count(id) as Total'))->where('idmonthi','=', $id)->get()->toArray(); return view('DeThi::dethi')->with('socaucuachuong', $socaucuachuong); }
My Blade file:
$('select').select(); function get_units(id) { var list = $('#dschuong'); list.empty(); var url = ""+'/'+ id; var success = function (result) { if (result.length <= 0) { var item = '<div class="input-field"><input type="text" disabled value="Môn này hiện chưa có câu hỏi nào"></div>'; list.append(item); } else { for (i = 0; i < result.length; i++) { var item = '<div class="input-field"><label for="unit-' + result[i].chuong + '">Nhập số câu hỏi chương ' + result[i].chuong + ' (có ' + result[i].Total + ' câu) <span class="failed">(*)</span></label><input type="number" max="' + result[i].Total + '" class="unit_input" onchange="set_sum(' + result[i].Total + ')" name="unit-' + result[i].chuong + '" id="unit-' + result[i].chuong + '" required></div>'; list.append(item); } } }; $.get(url, success); }
My Route file:
Route::post('socaucuachuong', 'DeThiController@socaucuachuong')->name('dethi.socaucuachuong');
https://stackoverflow.com/questions/67352805/how-to-pass-an-array-data-from-controller-to-blade-file-laravel May 02, 2021 at 11:44AM
没有评论:
发表评论