-2

I want to create a custom function in Laravel so that I can use it in the blade.

1 Answers1

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;

}