#2677 store module imp.

This commit is contained in:
Diatrex 2020-11-19 17:43:14 +03:00
parent 907d31fcac
commit b479c89399
3 changed files with 48 additions and 1 deletions

View File

@ -1,4 +1,4 @@
function crudAjax(params, url, type, callback, async = false) {
function crudAjax(params, url, type, callback = () => {}, async = false) {
return $.ajax({
type: type,
data: params,

View File

@ -1,6 +1,9 @@
<?php namespace Visiosoft\LocationModule\Http\Controller;
use Anomaly\Streams\Platform\Http\Controller\PublicController;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
use Visiosoft\LocationModule\Country\Contract\CountryRepositoryInterface;
use Visiosoft\LocationModule\District\Contract\DistrictRepositoryInterface;
@ -112,4 +115,43 @@ class AjaxController extends PublicController
return $query->orderBy($sorting_column, $sorting_type)->get();
}
public function findLocation()
{
try {
$validator = Validator::make(request()->all(), [
'type' => [
'required',
Rule::in(['countries', 'cities', 'districts', 'neighborhoods', 'village'])
],
'id' => 'required|exists:location_' . request()->type,
]);
if ($validator->fails()) {
throw new \Exception($validator->messages()->first());
}
$dBName = 'location_' . request()->type;
$location = DB::table($dBName)
->join(
$dBName . '_translations as location_trans',
$dBName . '.id',
'=',
'location_trans.entry_id'
)
->where($dBName . '.id', request()->id)
->first();
return [
'success' => true,
'data' => $location
];
} catch (\Exception $e) {
return [
'success' => false,
'msg' => $e->getMessage()
];
}
}
}

View File

@ -76,6 +76,7 @@ class LocationModuleServiceProvider extends AddonServiceProvider
'admin/location/neighborhoods/create' => 'Visiosoft\LocationModule\Http\Controller\Admin\NeighborhoodsController@create',
'admin/location/neighborhoods/edit/{id}' => 'Visiosoft\LocationModule\Http\Controller\Admin\NeighborhoodsController@edit',
// AjaxController
'ajax/getCountry' => [
'as' => 'location::getCountry',
'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getCountries'
@ -97,6 +98,10 @@ class LocationModuleServiceProvider extends AddonServiceProvider
'as' => 'location::getVillage',
'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getVillage'
],
'api/find-location' => [
'as' => 'visiosoft.module.location::api_find_location',
'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@findLocation'
],
];
/**