Laravel Image

In this tutorial, you’ll learn how to convert a string to uppercase in Laravel using both a controller method and a Blade template.

Part 1: Converting String to Uppercase in Laravel Controller

Step1: Create a New Controller

  1. Open your Laravel project’s terminal.
  2. Use the php artisan make:controller command to create a new controller. For instance, create an “UppercaseController”:
php artisan make:controller UppercaseController

Step2: Implement Uppercase Conversion

  1. Open the newly created UppercaseController.php file in the app/Http/Controllers directory.
  2. In a controller method, use the Str::upper() function to convert a string to uppercase:
use Illuminate\Support\Str;

// ...

public function toUppercase($inputString)
    $uppercaseString = Str::upper($inputString);
    return view('uppercase', ['inputString' => $inputString, 'uppercaseString' => $uppercaseString]);

Step3: Define Route

  1. Open the routes/web.php file.
  2. Define a route that uses the toUppercase method in the UppercaseController:
Route::get('/uppercase/{input}', 'UppercaseController@toUppercase');

Part 2: Displaying Uppercase String in Laravel Blade Template

Step1: Create a Blade View

  1. Navigate to your Laravel project’s resources/views directory.
  2. Create a new Blade view file. For instance, name it “uppercase.blade.php”.

Step2: Display Uppercase String in Blade Template

  1. Open the “uppercase.blade.php” file.
  2. Inside the Blade template, display the uppercase string passed from the controller:
<!DOCTYPE html>
    <title>String to Uppercase Conversion</title>
    <p>Uppercase String Controller: {{ $uppercaseString}}</p>
    <p>Uppercase String Blade: {{ Str::upper($inputString) }}</p>


Congratulations on mastering string-to-uppercase conversion in Laravel using controller methods and Blade templates. This versatile technique enhances your ability to manipulate text throughout your Laravel applications. Explore and integrate this method to efficiently transform strings to Uppercase. Happy coding!

Read More