Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

amit123's avatar

using enviroment variables in Laravel view doesn't work

hey,

I discovered a phenomenon in Blade that I cannot explain or handle at all.

In the store function in UsersControllers I save the directory of a user.

A directory typically looks like (BasePath)(FormRequestPath)

The Base Path is defined in my .env file. In config/app.php I also say : 'base_path' => env('BASE_PATH', '/srv/ftp'), And then I get it in my controller store function using config() and finally store there full path in my DB. All this actually works fine.

Now it starts getting weired. In my show view I want to get the full path back but when do

{{dd($user->directory)}} // prints only FormRequestPath

{{dd($user)}} // prints an object that contains a directory attribute with the full path

can you explain me what laravel exactly does there and what I am doing wrong?

Thanks Amit

0 likes
6 replies
amit123's avatar

dd($user->home_directory) // "/some_path/ssss"

dd($user) //

User {#219 ▼

#primaryKey: "name"

+incrementing: false

#fillable: array:10 [▶]

#hidden: array:1 [▶]

#connection: "mysql"

#table: null

#keyType: "int"

#with: []

#withCount: []

#perPage: 15

+exists: true

+wasRecentlyCreated: false

#attributes: array:13

[▼ "name" => "cf1arWGHz5TI"

"type" => "customer"

"password" => "3g17vv9V57B1"

"home_directory" => "/srv/.../clients/some_path/ssss"

"shell" => "/sbin/nologin"

"uid" => 79594

"gid" => 95978

"is_hidden" => 0

"comment" => null

"description" => null

"created_at" => "2017-10-30 10:41:02"

"updated_at" => "2017-10-30 14:11:23"

"deleted_at" => null

]

#original: array:13 [▶]

#changes: []

#casts: []

#dates: []

#dateFormat: null

#appends: []

#dispatchesEvents: []

#observables: []

#relations: array:1 [▶]

#touches: []

+timestamps: true

#visible: []

#guarded: array:1 [▶]

#rememberTokenName: "remember_token"

#forceDeleting: false

Edit: sorry for the mess. is there any way to post dumps or code on a nice way here?

mushood's avatar

I tried to reproduce. I dont get it.

Maybe it is evaluating the "..." in the url path

amit123's avatar

there is no "...". I just removed some parts that might be sensitive. so it actually should work the way I think?

thanks anyway

amit123's avatar

The reason for that phenomenon was an accessor defined by a co-worker in the User Model.

Please or to participate in this conversation.