Created
October 12, 2017 13:24
-
-
Save mmarin49/cf259dd3b07d793b7786b72ba3a2b432 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace PizzaApp\App\Http\Requests; | |
use Illuminate\Foundation\Http\FormRequest; | |
class IngredientRequest extends FormRequest | |
{ | |
/** | |
* Determine if the user is authorized to make this request. | |
* | |
* @return bool | |
*/ | |
public function authorize() | |
{ | |
return auth()->user()->role_id === 1; | |
} | |
/** | |
* Get the validation rules that apply to the request. | |
* | |
* @return array | |
*/ | |
public function rules() | |
{ | |
switch ($this->method()){ | |
case 'GET': | |
case 'DELETE': | |
return []; | |
case 'POST' | |
return[ | |
'name' => 'required|unique:ingredients|max:255', | |
'price' => 'required' | |
]; | |
case 'PUT': | |
case 'PATCH': | |
return[ | |
'name' => 'required|max:255|unique:ingredients,name'.$this->segment(3), | |
'price' => 'required' | |
] | |
default:break; | |
} | |
} | |
/** | |
* @return array; | |
*/ | |
public function messages() | |
{ | |
return[ | |
'name.required' => 'El nombre del ingrediente es requerido' | |
'name.unique' => 'Este ingrediente ya existe' | |
'price.required' => 'El precio es requerido' | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment