Я задавал этот вопрос дважды, но не получил никакого ответа, у меня есть две таблицы: Страна и Регион, поэтому, чтобы получить все регионы, вы должны выбрать country_id, который я сделал с обычной таблицей, но как я могу сделать это, используя ajax спасибо Вы заранее
Модель региона:
public function getRegionsByCountryID($countryID)
{
return $this
->leftJoin('countries', $this->table.'.country_id', '=', 'countries.id')
->select
(
$this->table.'.*',
'countries.name as country_name'
)
->where('country_id','=',$countryID)
->orderBy('id','asc')
->get();
}
Jquery
$.ajax({
url:"{{ route('get-regions') }}",
type: 'GET',
data: {
'country_id': country_id
},
success: function(data){
},
});
});
Контроллер
public function getData(Request $request)
{
$data = $this->SourceData->getRegionsByCountryID($request->input('country_id'));
return Datatables::of($data)
->addIndexColumn()
->addColumn('Actions', function($data) {
return '....';
})
->rawColumns(['Actions'])
->make(true);
}
Blade
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered datatable">
<thead>
<tr>
<th>Id</th>
<th>No</th>
<th>Name</th>
<th>Country</th>
<th>Avaliable</th>
<th width="150" class="text-center">Action</th>
</tr>
</thead>
</table>
</div>
</div>