Inventory Sources Validation Added
This commit is contained in:
parent
1948381a52
commit
a4e6ed1945
|
|
@ -50,19 +50,22 @@
|
|||
<textarea class="control" id="description" name="description">{{ old('description') }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-group" :class="[errors.has('latitude') ? 'has-error' : '']">
|
||||
<label for="latitude">{{ __('admin::app.settings.inventory_sources.latitude') }}</label>
|
||||
<input class="control" id="latitude" name="latitude" value="{{ old('latitude') }}"/>
|
||||
<input class="control" id="latitude" name="latitude" value="{{ old('latitude') }}" v-validate="'between:-90,90'"/>
|
||||
<span class="control-error" v-if="errors.has('latitude')">@{{ errors.first('latitude') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-group" :class="[errors.has('longitude') ? 'has-error' : '']">
|
||||
<label for="longitude">{{ __('admin::app.settings.inventory_sources.longitude') }}</label>
|
||||
<input class="control" id="longitude" name="longitude" value="{{ old('longitude') }}"/>
|
||||
<input class="control" id="longitude" name="longitude" value="{{ old('longitude') }}" v-validate="'between:-180,180'"/>
|
||||
<span class="control-error" v-if="errors.has('longitude')">@{{ errors.first('longitude') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-group" :class="[errors.has('priority') ? 'has-error' : '']">
|
||||
<label for="priority">{{ __('admin::app.settings.inventory_sources.priority') }}</label>
|
||||
<input class="control" id="priority" name="priority" value="{{ old('priority') }}"/>
|
||||
<input class="control" id="priority" name="priority" value="{{ old('priority') }}" v-validate="'numeric'"/>
|
||||
<span class="control-error" v-if="errors.has('priority')">@{{ errors.first('priority') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
|
|
|
|||
|
|
@ -52,19 +52,22 @@
|
|||
<textarea class="control" id="description" name="description">{{ old('description') ?: $inventorySource->description }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-group" :class="[errors.has('latitude') ? 'has-error' : '']">
|
||||
<label for="latitude">{{ __('admin::app.settings.inventory_sources.latitude') }}</label>
|
||||
<input class="control" id="latitude" name="latitude" value="{{ old('latitude') ?: $inventorySource->latitude }}"/>
|
||||
<input class="control" id="latitude" name="latitude" value="{{ old('latitude') ?: $inventorySource->latitude }}" v-validate="'between:-90,90'"/>
|
||||
<span class="control-error" v-if="errors.has('latitude')">@{{ errors.first('latitude') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-group" :class="[errors.has('longitude') ? 'has-error' : '']">
|
||||
<label for="longitude">{{ __('admin::app.settings.inventory_sources.longitude') }}</label>
|
||||
<input class="control" id="longitude" name="longitude" value="{{ old('longitude') ?: $inventorySource->longitude }}"/>
|
||||
<input class="control" id="longitude" name="longitude" value="{{ old('longitude') ?: $inventorySource->longitude }}" v-validate="'between:-180,180'"/>
|
||||
<span class="control-error" v-if="errors.has('longitude')">@{{ errors.first('longitude') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-group" :class="[errors.has('priority') ? 'has-error' : '']">
|
||||
<label for="priority">{{ __('admin::app.settings.inventory_sources.priority') }}</label>
|
||||
<input class="control" id="priority" name="priority" value="{{ old('priority') ?: $inventorySource->priority }}"/>
|
||||
<input class="control" id="priority" name="priority" value="{{ old('priority') ?: $inventorySource->priority }}" v-validate="'numeric'"/>
|
||||
<span class="control-error" v-if="errors.has('priority')">@{{ errors.first('priority') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
|
|
|
|||
|
|
@ -3,19 +3,20 @@
|
|||
namespace Webkul\Inventory\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Inventory\Http\Requests\InventorySourceRequest;
|
||||
use Webkul\Inventory\Repositories\InventorySourceRepository;
|
||||
|
||||
class InventorySourceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* InventorySourceRepository object
|
||||
* Inventory source repository instance.
|
||||
*
|
||||
* @var \Webkul\Inventory\Repositories\InventorySourceRepository
|
||||
*/
|
||||
|
|
@ -59,24 +60,11 @@ class InventorySourceController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store()
|
||||
public function store(InventorySourceRequest $inventorySourceRequest)
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'code' => ['required', 'unique:inventory_sources,code', new \Webkul\Core\Contracts\Validations\Code],
|
||||
'name' => 'required',
|
||||
'contact_name' => 'required',
|
||||
'contact_email' => 'required|email',
|
||||
'contact_number' => 'required',
|
||||
'street' => 'required',
|
||||
'country' => 'required',
|
||||
'state' => 'required',
|
||||
'city' => 'required',
|
||||
'postcode' => 'required',
|
||||
]);
|
||||
$data = $inventorySourceRequest->all();
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
$data['status'] = !isset($data['status']) ? 0 : 1;
|
||||
$data['status'] = ! isset($data['status']) ? 0 : 1;
|
||||
|
||||
Event::dispatch('inventory.inventory_source.create.before');
|
||||
|
||||
|
|
@ -108,24 +96,11 @@ class InventorySourceController extends Controller
|
|||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update($id)
|
||||
public function update(InventorySourceRequest $inventorySourceRequest, $id)
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'code' => ['required', 'unique:inventory_sources,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
|
||||
'name' => 'required',
|
||||
'contact_name' => 'required',
|
||||
'contact_email' => 'required|email',
|
||||
'contact_number' => 'required',
|
||||
'street' => 'required',
|
||||
'country' => 'required',
|
||||
'state' => 'required',
|
||||
'city' => 'required',
|
||||
'postcode' => 'required',
|
||||
]);
|
||||
$data = $inventorySourceRequest->all();
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
$data['status'] = !isset($data['status']) ? 0 : 1;
|
||||
$data['status'] = ! isset($data['status']) ? 0 : 1;
|
||||
|
||||
Event::dispatch('inventory.inventory_source.update.before', $id);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Inventory\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Webkul\Core\Contracts\Validations\Address;
|
||||
use Webkul\Core\Contracts\Validations\AlphaNumericSpace;
|
||||
use Webkul\Core\Contracts\Validations\Code;
|
||||
use Webkul\Core\Contracts\Validations\PhoneNumber;
|
||||
|
||||
class InventorySourceRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the Configuraion is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$id = request('id');
|
||||
|
||||
$uniqueCode = 'unique:inventory_sources,code,' . $id ?? 'unique:inventory_sources,code';
|
||||
|
||||
return [
|
||||
'code' => ['required', $uniqueCode, new Code],
|
||||
'name' => ['required'],
|
||||
'latitude' => ['numeric', 'between:-90,90'],
|
||||
'longitude' => ['numeric', 'between:-180,180'],
|
||||
'priority' => ['numeric'],
|
||||
'contact_name' => ['required', new AlphaNumericSpace],
|
||||
'contact_email' => ['required', 'email'],
|
||||
'contact_number' => ['required', new PhoneNumber],
|
||||
'street' => ['required', new Address],
|
||||
'country' => ['required', new AlphaNumericSpace],
|
||||
'state' => ['required', new AlphaNumericSpace],
|
||||
'city' => ['required', new AlphaNumericSpace],
|
||||
'postcode' => ['required'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue