Answers for "laravel update request validation"

PHP
1

laravel request validation rules for create and update

public function rules()
    {
        $rules = [
            'name' => 'required|string|unique:products|max:255',
        ];

        if (in_array($this->method(), ['PUT', 'PATCH'])) {
            $product = $this->route()->parameter('product');

            $rules['name'] = [
                'required',
                'string',
                'max:255',
                Rule::unique('loan_products')->ignore($product),
            ];
        }

        return $rules;
    }
Posted by: Guest on August-30-2020
0

laravel rule unique where

'required|email|unique:company_users,email_address,NULL,id,company_id,' . $request->company_id
Posted by: Guest on October-09-2020
0

laravel request validate

public function store(Request $request)
{
    $validated = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ]);

    // The blog post is valid...
}
Posted by: Guest on November-04-2021

Code answers related to "laravel update request validation"

Browse Popular Code Answers by Language