Home > Blockchain >  Try Catch using double question mark(??) in laravel view(blade) does'nt work
Try Catch using double question mark(??) in laravel view(blade) does'nt work

Time:05-05

I have an issue on my script. If i write :

{{ ($data->classroom??'' == $clr->id) ? 'checked' : '' }}

It is working.

But i can't do it, because $data->classroom would be parameter to compare of lists of $clr->id (radio button purpose).

But if i write :

{{ ($clr->id == $data->classroom??'') ? 'checked' : '' }}

The null safety(??) doesn't work.

Thank you in advance :)

CodePudding user response:

The double question mark, also called null coalescing operator is, in your case, ran after the == operation. Soo if you want to achieve this, you need to put parenthesis like that: ($clr->id == ($data->classroom??''))[...]

  • Related