RequestProduct.php 1.36 KB
Newer Older
Pancholin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php

namespace Onestartup\ProductResource\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RequestProduct extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
26 27 28 29 30
        if ($this->get("_method") == "PUT" || $this->get("_method") == "PATCH"){
            $slug = 'required|max:455|unique:products_resource,slug,'.$this->route("product");
        }else{  
            $slug = 'required|max:455|unique:products_resource,slug';
        }   
Pancholin committed
31 32
        return [
            'name' => 'required|max:355',
33
            'slug' => $slug,
Pancholin committed
34 35 36 37 38 39 40 41 42 43 44 45 46
            'description'=> 'required',
            'active' => 'required|boolean',
            'publication_date' => 'required',
            'extra1' => 'max:455',
            'extra2' => 'max:455',
            'extra3' => 'max:455',
            'extra4' => 'max:455',
            'extra5' => 'max:455',
            'extra6' => 'max:455',
            'extra7' => 'max:455',
            'extra8' => 'max:455',
            'extra9' => 'max:455',
            'extra10' => 'max:455',
47 48
            'category_id' => 'required|numeric',
            'cover' => 'image'
Pancholin committed
49 50 51
        ];
    }
}