0

How do you do ?

I would like to ask about symbol @ in PHP $variable in blade laravel 5. This is the code that I get, but unfortunately the previous programmer was is lost.

enter image description here

Please note at this -> {{ old('title_id', @$result->title_id) }}.

Why using @ ? and what is different with {{ old('title_id', $result->title_id) }} without @.

Thank you very much

Dimas
  • 67
  • 9

1 Answers1

1

The @ is used as error control operator at php. Php will not throw any error generated from the exception.

{{ old('title_id', @$result->title_id) }}. The purpose to use the @ symbol here is to prevent the program from throw exception like "try to call title_id from an empty object". Instead it goes with define the variable with null value. It sometimes usefull when you want to do the edit / create on the same blade file.

If you dont use @ symbol, you must handle if the variable is empty or not first and you ended up with code like

{{ old('title_id', $result ? $result->title_id : '') }}

You can read more detail at php documentation.

Wailan Tirajoh
  • 481
  • 5
  • 17