snipe-it/app/Http/Requests/Request.php

36 lines
900 B
PHP
Raw Normal View History

2016-03-25 01:18:05 -07:00
<?php
namespace App\Http\Requests;
use App\Helpers\Helper;
2016-03-25 01:18:05 -07:00
use Illuminate\Foundation\Http\FormRequest;
abstract class Request extends FormRequest
{
protected $rules = [];
public function json($key = null, $default = null)
{
if ($this->ajax() || $this->wantsJson()) {
2022-02-08 12:09:40 -08:00
json_decode($this->getContent(), false, 512, JSON_THROW_ON_ERROR); // ignore output, just throw
}
return parent::json($key, $default);
}
2016-03-25 01:18:05 -07:00
public function rules()
{
return $this->rules;
}
public function response(array $errors)
{
if ($this->ajax() || $this->wantsJson()) {
return Helper::formatStandardApiResponse('error', null, $errors);
}
return $this->redirector->to($this->getRedirectUrl())
->withInput($this->except($this->dontFlash))
->withErrors($errors, $this->errorBag);
}
2016-03-25 01:18:05 -07:00
}