I want to create a custom function in Laravel so that I can use it in the blade.
Asked
Active
Viewed 187 times
1 Answers
0
Step 1: create helpers.php file in app folder like app/helpers.php Step 2: add helpers.php in composer.json file in Laravel project Step 3: after adding file fire composer dump-autoload command step 4: write your custom function in helpers.php step 5: now, you can use this function in blade file like PHP builtin function
function alernateCapital($string){
$string_count = strlen($string);
$string_split = str_split($string);
$array = [];
for($i=0; $i<=$string_count-1; $i++){
if($i == 0){
array_push($array, $string_split[$i]);
}else{
if($i % 2){
array_push($array, strtoupper($string_split[$i]));
}else{
array_push($array, strtolower($string_split[$i]));
}
}
}
$new_string = implode(" ",$array);
return $new_string;
}

suhail gour
- 1
- 2
-
Are you still looking for answers or did you solve by yourself? – Kevin Y Jan 30 '22 at 07:08
-
I already solved myself, I uploaded this because maybe it helps others to understand. – suhail gour Jan 30 '22 at 07:14