2

I have a function in a model that can return either true or false.

I use this function inside a view and first thing I discovered when I called it is

{{ Setting::isDesktop() }}

that it outputs 1 instead of true if I do that inside blade file. If I do dd({{ Setting::isDesktop() }}) then it will print true or false.

Second thing that is giving me a problem is that, if the value is false then nothing is printed when doing this from blade file. I need something to be printed either 1/0 or true/false

Why does boolean get converted to number inside blade files but not controllers? How can I get something printed when isDesktop returns false? Right now it prints nothing in that case.

manian
  • 1,418
  • 2
  • 16
  • 32
niko craft
  • 2,893
  • 5
  • 38
  • 67

1 Answers1

1

There are few methods you can achieve your requirement.
Here are couple of them,
1. Use Ternary operator like below,

{{ Setting::isDesktop() ? 'true' : 'false' }}

2. Use var_export as shown below,

{{ var_export(Setting::isDesktop()) }}

manian
  • 1,418
  • 2
  • 16
  • 32