Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: how to get direct config value in blade template?

i want to get config value in blade.

config/define.php
<?php
return [
    'show' => array(1 => 'Show',0 => 'Hide' ),
];

I found a code

{{ Config::get('define.show') }}

But i want use:

{{ $showarray = Config::get('define.show') }}

@foreach ($master as $pt)
{{ $showarray[$pt->show_flag] }}
@endforeach

But it does not work. Help me please!

like image 533
Hưng Trịnh Avatar asked Dec 05 '18 11:12

Hưng Trịnh


1 Answers

You can do it by -

@foreach ($master as $pt)
    {{ Config::get('define.show.' . $pt->show_flag) }} // concatenate the value
@endforeach

Or by using @php tag -

@php
    $showarray = Config::get('define.show');
@endphp

@foreach ($master as $pt)
    {{ $showarray[$pt->show_flag] }}
@endforeach

You can also access the configs by using config().

like image 187
Sougata Bose Avatar answered Oct 06 '22 22:10

Sougata Bose