Answer the question
In order to leave comments, you need to log in
How to write functions in index.blade.php in laravel?
I'm starting to learn laravel. I need to write a small function in one line in the index file. To check it later with @if ( ). So where should I write this function? Preferably not in the Controller :)
Well, or if in the Controller, then how to write foreach @if functions there?
Anyone who does not laugh at the fool, but will help I will be grateful)
Answer the question
In order to leave comments, you need to log in
It is better to move the logic to the controller, make a calculation and pass the result to the view, and then check it in the blade.
But also because blade is still a php file, it allows you to use php code, look towards the @php directive
Create a file app/helpers.php
(name and location doesn't matter)
In it, define the desired function(s).
Write it in composer.json
"autoload": {
"psr-4": {
...
},
"files": [
"app/helpers.php"
]
},
composer du
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question