How to Truncate String in Laravel?

By Hardik Savani November 5, 2023 Category : Laravel

Hi Guys,

Now, let's see a tutorial of how to truncate string in laravel. I explained simply step by step laravel limit string length. Here you will learn how to cut string in laravel. you can see laravel blade limit string length. Alright, let’s dive into the steps.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 versions.

Laravel provide string helper using Str facade. we can set limit string length in blade file or controller file using Str::limit() function.

So, let's see the below examples:

Example 1: Laravel Limit string length in Blade File


<!DOCTYPE html>



<title>How to Truncate String in Laravel? -</title>

<link href="" rel="stylesheet">



<div class="container">

<h1>How to Truncate String in Laravel? -</h1>

<table class="table table-bordered data-table">









@foreach($posts as $post)


<td>{{ $post->id }}</td>

<td>{{ $post->title }}</td>

<td>{{ Str::limit($post->body, 50) }}</td>









Example 2: Laravel Limit string length in Controller File



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\Post;

use Illuminate\Support\Str;

class PostController extends Controller



* Write code on Method


* @return response()


public function index(Request $request)


$post = Post::first();

$body = Str::limit($post->body, 50);

return view('posts', compact('post'));



I hope it can help you...

Tags :