1

I have used {{$property.[Rent or Sale]}} or {{$property[Rent or Sale]}} for getting a value for the key Rent or Sale.

It is showing syntax error unexpected')' expected ']'.

2
  • So you mean to say it is giving an error message when you have key name separated with space? @SaibalChakravarty Commented Nov 22, 2016 at 8:24
  • Yes @PassionInfinite Commented Nov 22, 2016 at 8:42

4 Answers 4

1

This one works for me: config('menus.main_menu.Main\ Section') }}

So probably if you try to escape the space with \ it might work.

Sign up to request clarification or add additional context in comments.

Comments

0

Firstly, According to best practices of PHP, we should never use space in array keys.

Secondly, This is fixed by me and my friend @curos. The issue was with the improper regular expression which was interpreting 'or' as default keyword. The following is the method having regex problem.

     public function compileEchoDefaults($value)
     {
       return preg_replace('/^(?=\$)(.+?)(?:\s+or\s+)(.+?)$/s', 'isset($1) ? $1 : $2', $value);
     }

Which is updated as following:

     public function compileEchoDefaults($value)
     {
        return preg_replace('/^(?=\$)([^\'"]+?)(?:\s+or\s+)(.+?)$/s', 'isset($1) ? $1 : $2', $value);
     }

The above method is in vendor/laravel/framework/src/compilers/BladeCompiler.php

This updated regular expression will not interpret 'or' as keyword.

please see : This bug has been fixed by laravel

Comments

0

your syntax was wrong you have to write it like {{$property.Rent}} {{$property.Sale}}

Comments

0

Try using like this.

<td> <? echo $user->{'Rent or Sale'}; ?> </td>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.