Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the purposes symbol @ in PHP $variable at blade laravel 5?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading