mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Just use inline validation instead of form request, since it's a one-off
This commit is contained in:
parent
0ca85f8a8a
commit
e5a5de6a0d
|
@ -8,7 +8,6 @@ use App\Models\Component;
|
|||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Models\Asset;
|
||||
use App\Http\Requests\ComponentCheckoutRequest;
|
||||
use Auth;
|
||||
use Config;
|
||||
use DB;
|
||||
|
@ -19,6 +18,8 @@ use Redirect;
|
|||
use Slack;
|
||||
use Str;
|
||||
use View;
|
||||
use Validator;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* This class controls all actions related to Components for
|
||||
|
@ -302,9 +303,12 @@ class ComponentsController extends Controller
|
|||
* @param int $componentId
|
||||
* @return Redirect
|
||||
*/
|
||||
public function postCheckout(ComponentCheckoutRequest $request, $componentId)
|
||||
public function postCheckout(Request $request, $componentId)
|
||||
{
|
||||
// Check if the component exists
|
||||
|
||||
|
||||
|
||||
// Check if the component exists
|
||||
if (is_null($component = Component::find($componentId))) {
|
||||
// Redirect to the component management page with error
|
||||
return redirect()->to('components')->with('error', trans('admin/components/message.not_found'));
|
||||
|
@ -312,6 +316,19 @@ class ComponentsController extends Controller
|
|||
return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions'));
|
||||
}
|
||||
|
||||
|
||||
$max_to_checkout = $component->numRemaining();
|
||||
$validator = Validator::make($request->all(),[
|
||||
"asset_id" => "required",
|
||||
"assigned_qty" => "required|numeric|between:1,$max_to_checkout"
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect()->back()
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
$admin_user = Auth::user();
|
||||
$asset_id = e(Input::get('asset_id'));
|
||||
|
||||
|
@ -320,7 +337,7 @@ class ComponentsController extends Controller
|
|||
// Redirect to the component management page with error
|
||||
return redirect()->to('admin/components')->with('error', trans('admin/components/message.asset_does_not_exist'));
|
||||
}
|
||||
|
||||
|
||||
// Update the component data
|
||||
$component->asset_id = $asset_id;
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class ComponentCheckoutRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user 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()
|
||||
{
|
||||
return [
|
||||
"asset_id" => 'required',
|
||||
"assigned_qty" => 'required|numeric|min:1',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -54,13 +54,10 @@
|
|||
<div class="form-group {{ $errors->has('assigned_qty') ? ' has-error' : '' }}">
|
||||
<label for="assigned_qty" class="col-md-3 control-label">{{ trans('general.qty') }}
|
||||
<i class='icon-asterisk'></i></label>
|
||||
<div class="col-md-1">
|
||||
<input class="form-control" type="text" name="assigned_qty" id="assigned_qty" value="{{ Input::old('assigned_qty') }}" />
|
||||
<div class="col-md-9">
|
||||
<input class="form-control" type="text" name="assigned_qty" id="assigned_qty" style="width: 70px;" value="{{ Input::old('assigned_qty') }}" />
|
||||
{!! $errors->first('assigned_qty', '<br><span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
{{ $component->numRemaining() }} Max
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue