Eshop-Laravel/app/Http/Requests/ProductRequest.php
2019-10-18 12:25:37 +03:00

31 lines
729 B
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
class ProductRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules(Request $request)
{
$unique = !empty($request['item_id']) ? ',' . $request['item_id'] :'';
return [
'categorie_id' => 'required|numeric',
'title' => 'required',
'url' => 'required|regex:/^[a-z\d-]+$/|unique:products,url'.$unique,
'price' => 'required|numeric',
'stock' => 'required|numeric',
'sale' => 'required|numeric',
'body' => 'required',
'image' => 'image',
];
}
}