php class properties, Laravel

Sorry it is my first question. I am new in PHP and Laravel.

I try defined property for some controller and i get error :

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)

Constant expression contains invalid operations

This my controller code :

<?php

    namespace App\Http\Controllers\...;

    use Illuminate\Http\Request;
    use App\Http\Controllers\Controller;
    use App\Customer;
    use App\City;
    use Illuminate\Database\Eloquent\Builder;
    use Carbon\Carbon;

    use Illuminate\Support\Facades\Auth;

    class CatalogController extends Controller
    {
        protected $user = Auth::user();

        function user() {
           $user = optional(Auth::user())->load(['city']);
           return $user;
        }
    }

In php.net i read this : Class member variables may be intialize ..., but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

I assume that this rule is not executed in my code. I'm right?


Ответы (0 шт):