简体   繁体   中英

Laravel 5 form request on update

I don't understand why this doesn't work, i have searched the forums and read the official documentation, obviously I'm making a silly mistake:

public function rules()
{
    $customer = Customer::find($this->customers);
    return [
        'data.name'       => 'required|unique:customers,name,1'
    ];
}

That is a CustomerUpdateFormRequest that i created, i manually typed the customer id which is 1 in the rule, also with: 'data.name' => 'required|unique:customers,name,'.$customer->id,

The problem is that it still doesnt pass the unique validation, i giving me the Customer already exists error even after manually or dynamically type the customer id.

I read this http://laravel.com/docs/5.0/validation and https://laracasts.com/discuss/channels/requests/laravel-5-validation-request-how-to-handle-validation-on-update and I 'Believe' that my code is correct, why is not working?

The code above is working just fine, no syntax errors or logic, the problem was in the database, there was another customer with the same data inserted i guess before the validation form was created.

I dont know if i should delete this question or leave it here, anyway the code its fine if u have any problems like mine PLEASE CHECK YOUR DB.

Thanks!

public function rules()
{

    $customer= $this->route('customer'); //$this->('route-name')

    return [
        'data.name'       => 'required|unique:customers,name,' . $customer->id
    ];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM