mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
8a782bf34a
* Set user if asset is checked out to user. fixes email problems. * Use sometimes validation to ignore this when no values are present. * Move Actionlog details to a presenter and port the activity table to use it. Still need to port other parts of the application, but this consolidates a lot of logic. * Attempt test fix * Port users,licenses, and assets view to use the presenter to generate table values.
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Http\Requests\Request;
|
|
use App\Models\AssetModel;
|
|
use Session;
|
|
|
|
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|nullable',
|
|
'warranty_months' => 'numeric|nullable',
|
|
'physical' => 'integer|nullable',
|
|
'checkout_date' => 'date',
|
|
'checkin_date' => 'date',
|
|
'supplier_id' => 'integer|nullable',
|
|
'status' => 'integer|nullable',
|
|
'asset_tag' => 'required',
|
|
'purchase_cost' => 'numeric|nullable',
|
|
"assigned_user" => 'sometimes:required_without_all:assigned_asset,assigned_location',
|
|
"assigned_asset" => 'sometimes:required_without_all:assigned_user,assigned_location',
|
|
"assigned_location" => 'sometimes:required_without_all:assigned_user,assigned_asset',
|
|
];
|
|
|
|
$model = AssetModel::find($this->request->get('model_id'));
|
|
|
|
if (($model) && ($model->fieldset)) {
|
|
$rules += $model->fieldset->validation_rules();
|
|
}
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
public function response(array $errors)
|
|
{
|
|
$this->session()->flash('errors', Session::get('errors', new \Illuminate\Support\ViewErrorBag)
|
|
->put('default', new \Illuminate\Support\MessageBag($errors)));
|
|
\Input::flash();
|
|
return parent::response($errors);
|
|
}
|
|
}
|