Generate Random Number Within @if-directive
I am using
laravel 6 and I am currently using the following:
@if($randomNumb<0.5) // do sth @endif
My problem with the above code snippet is that I pre-calculate the random number in the backend and then hand it to the blade template. Therefore, I get all the time the same random number, if I am using the above code-snippet more than one time in my blade-template.
Any suggestions how to calculate a unique random number directly in the
Appreciate your replies!
There is nothing wrong with just calculating it right on the blade page each time you need it, especially if you need a unique value that would not have been passed from the controller.
@if(mt_rand(1, 100) < 50) // do something @endif
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?