Add function to get json data for select2
This commit is contained in:
parent
058baccedf
commit
015ea5ea1d
@ -35,17 +35,12 @@
|
|||||||
*
|
*
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
*/
|
*/
|
||||||
public function index(CityDataTable $dataTable, Request $request)
|
public function index(CityDataTable $dataTable)
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
||||||
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($request->province_id) && !empty($request->province_id)) {
|
|
||||||
$this->show($request);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
addVendor('chained-select');
|
addVendor('chained-select');
|
||||||
|
|
||||||
$countries = Country::all();
|
$countries = Country::all();
|
||||||
@ -111,9 +106,19 @@
|
|||||||
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
||||||
}
|
}
|
||||||
|
|
||||||
$cities = City::where('province_id', $request->province_id)->get();
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function select2(Request $request)
|
||||||
|
{
|
||||||
|
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
||||||
|
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
||||||
|
}
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
if ($request->has('province_id') && $request->province_id != '') {
|
||||||
|
$cities = City::where('province_id', $request->province_id)->get();
|
||||||
|
|
||||||
foreach ($cities as $row) {
|
foreach ($cities as $row) {
|
||||||
$result = [
|
$result = [
|
||||||
$row->id => $row->name,
|
$row->id => $row->name,
|
||||||
@ -121,10 +126,12 @@
|
|||||||
|
|
||||||
$data[] = $result;
|
$data[] = $result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
|
@ -35,15 +35,12 @@
|
|||||||
*
|
*
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
*/
|
*/
|
||||||
public function index(DistrictDataTable $dataTable, Request $request)
|
public function index(DistrictDataTable $dataTable)
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
||||||
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
||||||
}
|
}
|
||||||
if (isset($request->city_id) && !empty($request->city_id)) {
|
|
||||||
$this->show($request);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
addVendor('chained-select');
|
addVendor('chained-select');
|
||||||
$countries = Country::all();
|
$countries = Country::all();
|
||||||
return $dataTable->render($this->module->alias . '::district.index', compact('countries'));
|
return $dataTable->render($this->module->alias . '::district.index', compact('countries'));
|
||||||
@ -72,7 +69,7 @@
|
|||||||
$this->model::create($validated);
|
$this->model::create($validated);
|
||||||
echo json_encode(['status' => 'success', 'message' => $this->module->name . ' district created successfully.']);
|
echo json_encode(['status' => 'success', 'message' => $this->module->name . ' district created successfully.']);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
echo json_encode(['status' => 'error', 'message' => $this->module->name . ' district created failed.'. $e]);
|
echo json_encode(['status' => 'error', 'message' => $this->module->name . ' district created failed.' . $e]);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -103,7 +100,7 @@
|
|||||||
*/
|
*/
|
||||||
public function show(Request $request)
|
public function show(Request $request)
|
||||||
{
|
{
|
||||||
if(is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
||||||
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +118,30 @@
|
|||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function select2(Request $request)
|
||||||
|
{
|
||||||
|
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
||||||
|
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
if ($request->has('city_id') && $request->city_id != '') {
|
||||||
|
|
||||||
|
$districts = District::where('city_id', $request->city_id)->get();
|
||||||
|
|
||||||
|
foreach ($districts as $row) {
|
||||||
|
$result = [
|
||||||
|
'id' => $row->id,
|
||||||
|
'text' => $row->name,
|
||||||
|
];
|
||||||
|
|
||||||
|
$data[] = $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
|
@ -35,17 +35,12 @@
|
|||||||
*
|
*
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
*/
|
*/
|
||||||
public function index(ProvinceDataTable $dataTable, Request $request)
|
public function index(ProvinceDataTable $dataTable)
|
||||||
{
|
{
|
||||||
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
||||||
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($request->country_id) && !empty($request->country_id)) {
|
|
||||||
$this->show($request);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$countries = Country::all();
|
$countries = Country::all();
|
||||||
return $dataTable->render($this->module->alias . '::province.index', compact('countries'));
|
return $dataTable->render($this->module->alias . '::province.index', compact('countries'));
|
||||||
|
|
||||||
@ -64,9 +59,19 @@
|
|||||||
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
||||||
}
|
}
|
||||||
|
|
||||||
$provinces = Province::where('country_id', $request->country_id)->get();
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function select2(Request $request)
|
||||||
|
{
|
||||||
|
if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) {
|
||||||
|
abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !');
|
||||||
|
}
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
if ($request->has('country_id') && $request->country_id != '') {
|
||||||
|
$provinces = Province::where('country_id', $request->country_id)->get();
|
||||||
|
|
||||||
foreach ($provinces as $row) {
|
foreach ($provinces as $row) {
|
||||||
$result = [
|
$result = [
|
||||||
$row->id => $row->name,
|
$row->id => $row->name,
|
||||||
@ -74,7 +79,7 @@
|
|||||||
|
|
||||||
$data[] = $result;
|
$data[] = $result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@
|
|||||||
|
|
||||||
$("#{{$route[0].'_'.$route[1]}}_province_id").remoteChained({
|
$("#{{$route[0].'_'.$route[1]}}_province_id").remoteChained({
|
||||||
parents: "#{{$route[0].'_'.$route[1]}}_country_id",
|
parents: "#{{$route[0].'_'.$route[1]}}_country_id",
|
||||||
url: "/master/province"
|
url: "/master/province-select2"
|
||||||
});
|
});
|
||||||
|
|
||||||
Inputmask({
|
Inputmask({
|
||||||
|
@ -135,12 +135,12 @@
|
|||||||
|
|
||||||
$("#{{$route[0].'_'.$route[1]}}_province_id").remoteChained({
|
$("#{{$route[0].'_'.$route[1]}}_province_id").remoteChained({
|
||||||
parents: "#{{$route[0].'_'.$route[1]}}_country_id",
|
parents: "#{{$route[0].'_'.$route[1]}}_country_id",
|
||||||
url: "/master/province"
|
url: "/master/province-select2"
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#{{$route[0].'_'.$route[1]}}_city_id").remoteChained({
|
$("#{{$route[0].'_'.$route[1]}}_city_id").remoteChained({
|
||||||
parents: "#{{$route[0].'_'.$route[1]}}_province_id",
|
parents: "#{{$route[0].'_'.$route[1]}}_province_id",
|
||||||
url: "/master/city"
|
url: "/master/city-select2"
|
||||||
});
|
});
|
||||||
|
|
||||||
Inputmask({
|
Inputmask({
|
||||||
|
@ -136,17 +136,17 @@
|
|||||||
|
|
||||||
$("#{{$route[0].'_'.$route[1]}}_province_id").remoteChained({
|
$("#{{$route[0].'_'.$route[1]}}_province_id").remoteChained({
|
||||||
parents: "#{{$route[0].'_'.$route[1]}}_country_id",
|
parents: "#{{$route[0].'_'.$route[1]}}_country_id",
|
||||||
url: "/master/province"
|
url: "/master/province-select2"
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#{{$route[0].'_'.$route[1]}}_city_id").remoteChained({
|
$("#{{$route[0].'_'.$route[1]}}_city_id").remoteChained({
|
||||||
parents: "#{{$route[0].'_'.$route[1]}}_province_id",
|
parents: "#{{$route[0].'_'.$route[1]}}_province_id",
|
||||||
url: "/master/city"
|
url: "/master/city-select2"
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#{{$route[0].'_'.$route[1]}}_district_id").remoteChained({
|
$("#{{$route[0].'_'.$route[1]}}_district_id").remoteChained({
|
||||||
parents: "#{{$route[0].'_'.$route[1]}}_city_id",
|
parents: "#{{$route[0].'_'.$route[1]}}_city_id",
|
||||||
url: "/master/district"
|
url: "/master/district-select2"
|
||||||
});
|
});
|
||||||
|
|
||||||
Inputmask({
|
Inputmask({
|
||||||
|
@ -37,8 +37,15 @@
|
|||||||
Route::resource('card', CardController::class);
|
Route::resource('card', CardController::class);
|
||||||
Route::resource('country', CountryController::class);
|
Route::resource('country', CountryController::class);
|
||||||
Route::resource('province', ProvinceController::class);
|
Route::resource('province', ProvinceController::class);
|
||||||
|
Route::get('province-select2', [ProvinceController::class, 'select2'])->name('province.select2');
|
||||||
|
|
||||||
Route::resource('city', CityController::class);
|
Route::resource('city', CityController::class);
|
||||||
|
Route::get('city-select2', [CityController::class, 'select2'])->name('city.select2');
|
||||||
|
|
||||||
Route::resource('district', DistrictController::class);
|
Route::resource('district', DistrictController::class);
|
||||||
|
Route::get('district-select2', [DistrictController::class, 'select2'])->name('district.select2');
|
||||||
|
|
||||||
Route::resource('sub-district', SubDistrictController::class);
|
Route::resource('sub-district', SubDistrictController::class);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user