Reputation: 5644
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
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
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