Eshop-Laravel/app/Http/Requests/ProductRequest.php

32 lines
729 B
PHP
Raw Permalink Normal View History

2019-10-18 09:25:37 +00:00
<?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',
];
}
}