Zeeshan Ahmad
Zeeshan Ahmad

Reputation: 5644

Laravel - Can't put the id of authenticated user in array

I want to put the id of authenticated user in the associative array.

Code

const USER_RULES = [
    'email' => "required|unique:users,email," . Auth::user()->id . "|email",
];

Above code generates the following error:

Constant expression contains invalid operations

Upvotes: 2

Views: 292

Answers (2)

Oleksii Boiko
Oleksii Boiko

Reputation: 196

From official doc:

The value must be a constant expression, not (for example) a variable, a property, or a function call.

Upvotes: 3

krlv
krlv

Reputation: 2380

You can't use expressions like Auth::user()->id in the PHP constants. It's only possible to provide a scalar expression (numeric and string literals). Check documentation for details: http://php.net/manual/en/language.oop5.constants.php

Upvotes: 4

Related Questions