Update a record with a single field

Asked

Viewed 130 times

0

I’m using the L5-Repository in my project, but I’m having the following difficulty:

I have the code below to make the Slug is unique, but when I update it says Slug already exists, when in fact it is the Slug from the very record I am editing. How can I resolve this?

class LandingValidator extends LaravelValidator
{
    protected $rules = [
        ValidatorInterface::RULE_CREATE => [
            'slug' => 'required|unique:landings,slug',
        ],
        ValidatorInterface::RULE_UPDATE => [
            'slug' => 'required|unique:landings,slug',
        ],
   ];
}

I tried this way, but it didn’t work:

ValidatorInterface::RULE_UPDATE => [
    'slug' => 'required|unique:landings,slug,'.$landing->id,
],

Fatalerrorexception in Landingvalidator.php line 25:

syntax error, Unexpected '$Landing' (T_VARIABLE)

1 answer

0

I think your problem is something else. The mistake Parse error: syntax error, Unexpected T_VARIABLE means that PHP was not expecting the definition of a variable at any given time.

Check out this answer here to learn more about this error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.