9

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!

Hưng Trịnh
  • 947
  • 1
  • 12
  • 23

1 Answers1

15

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().

Sougata Bose
  • 31,517
  • 8
  • 49
  • 87