mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-24 04:03:34 -08:00
Trying to fix ajax asset validation
This I think gets us closer, but still not handling the validation on the asset properly. When I do a print_r of the validation in the other items, its looking for an error bag that looks something like this: ``` Illuminate\Support\MessageBag Object ( [messages:protected] => Array ( [name] => Array ( [0] => The name field is required. ) [seats] => Array ( [0] => The seats field is required. ) [category_id] => Array ( [0] => The category id field is required. ) ) [format:protected] => :message ) ``` Currently the Assets ajax returns: ``` [2019-05-24 06:52:06] develop.ERROR: array ( 'messages' => array ( 'model_id' => array ( 0 => 'The model id field is required.', ), 'status_id' => array ( 0 => 'The status id field is required.', ), 'asset_tag' => array ( 0 => 'The asset tag field is required.', ), ), ) ``` So not sure why it’s not working.
This commit is contained in:
parent
dd5d5cc07c
commit
5be5e3271d
|
@ -6,6 +6,8 @@ use App\Models\AssetModel;
|
|||
use Session;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Requests\Request;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
|
||||
class AssetRequest extends Request
|
||||
{
|
||||
|
@ -70,6 +72,8 @@ class AssetRequest extends Request
|
|||
/**
|
||||
* Handle a failed validation attempt.
|
||||
*
|
||||
* public function json($data = [], $status = 200, array $headers = [], $options = 0)
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||
* @return void
|
||||
*
|
||||
|
@ -77,7 +81,33 @@ class AssetRequest extends Request
|
|||
*/
|
||||
protected function failedValidation(Validator $validator)
|
||||
{
|
||||
\Log::error('failedValidation');
|
||||
throw new HttpResponseException(response()->json($validator->errors(), 'error', 422));
|
||||
// $status, $payload = null, $messages = null
|
||||
//$array['status'] = 'error';
|
||||
//$array['payload'] = null;
|
||||
$array['messages'] = [];
|
||||
//$array['errors'] = [];
|
||||
|
||||
if ($validator->errors()) {
|
||||
foreach ($validator->errors()->messages() as $field => $errors) {
|
||||
$array['messages'][$field] = $errors;
|
||||
//$array['errors'][$field] = $errors;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// $errors = $validator->errors();
|
||||
// \Log::debug('failedValidation');
|
||||
// \Log::debug('validator->errors()->all()');
|
||||
// \Log::debug(print_r($validator->errors()->all(), true));
|
||||
// \Log::debug('validator->errors()');
|
||||
// \Log::debug(print_r($validator->errors(), true));
|
||||
// \Log::debug('validator->errors()->messages()');
|
||||
// \Log::debug(print_r($validator->errors()->messages(), true));
|
||||
// \Log::debug('array');
|
||||
\Log::error($array);
|
||||
|
||||
throw new HttpResponseException(response()->json($array, 200));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue