PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 10, 2022

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

 February 10, 2022     laravel, laravel-5, laravel-blade, php     No comments   

Issue

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!


Solution

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



Answered By - Sougata Bose
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing