3 years ago

Requests & Rules

Posted 3 years ago by toneee

Hi All,

I am currently undertaking a task on my project to make sure all validation rules are correct and up to date. I have decided to move all rules into FormRequest. I have read the documents and have got a bit stuck and need some help.

Basically I have a profile page that has 2 forms

Form 1 is to update the profile photo Form 2 is to update name and email address

This is my ProfileRequest.php


namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ProfileRequest 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()
        return [
            'profile_picture' => 'image|mimes:jpeg,png,jpg|max:2048',
            'name' => 'required|string|max:255',
            'email' => 'required|unique:users|email',

The point at which i get stuck is if I update only the profile picture i get an error because of the name and email already being in the database with their current values. How do I add rule validation into this file to eliminate this issue? It is the same if I only update the name it errors on the email field and vice versa.

Thanks for any help!

Please sign in or create an account to participate in this conversation.