Skip to content

Instantly share code, notes, and snippets.

@mmarin49
Created October 12, 2017 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmarin49/cf259dd3b07d793b7786b72ba3a2b432 to your computer and use it in GitHub Desktop.
Save mmarin49/cf259dd3b07d793b7786b72ba3a2b432 to your computer and use it in GitHub Desktop.
<?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