2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
2016-03-25 19:26:22 -07:00
|
|
|
use App\Models\AssetModel;
|
2016-05-20 17:23:34 -07:00
|
|
|
use Session;
|
2016-06-22 12:27:41 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
class AssetRequest 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()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'name' => 'min:2|max:255',
|
|
|
|
'model_id' => 'required|integer',
|
|
|
|
'status_id' => 'required|integer',
|
|
|
|
'company_id' => 'integer',
|
|
|
|
'warranty_months' => 'integer|min:0|max:240',
|
2016-07-09 18:19:51 -07:00
|
|
|
'physical' => 'integer',
|
2016-06-10 16:36:46 -07:00
|
|
|
'checkout_date' => 'date',
|
|
|
|
'checkin_date' => 'date',
|
2016-03-25 01:18:05 -07:00
|
|
|
'supplier_id' => 'integer',
|
|
|
|
'status' => 'integer',
|
2016-06-10 16:36:46 -07:00
|
|
|
'asset_tag' => 'required',
|
2016-07-09 18:19:51 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
];
|
|
|
|
|
2016-03-25 19:26:22 -07:00
|
|
|
$model = AssetModel::find($this->request->get('model_id'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-06-22 12:27:41 -07:00
|
|
|
if (($model) && ($model->fieldset)) {
|
2016-03-25 01:18:05 -07:00
|
|
|
$rules += $model->fieldset->validation_rules();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function response(array $errors)
|
|
|
|
{
|
2016-05-20 17:23:34 -07:00
|
|
|
$this->session()->flash('errors', Session::get('errors', new \Illuminate\Support\ViewErrorBag)
|
|
|
|
->put('default', new \Illuminate\Support\MessageBag($errors)));
|
2016-06-09 18:28:49 -07:00
|
|
|
\Input::flash();
|
2016-05-20 17:23:34 -07:00
|
|
|
return parent::response($errors);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|