Question: I have code:

```
@foreach($tag->categories as $category)
    {{$loop->first ? '' : ','}} <a href="{{ route('showcategory', $category) }}">{{ $category->name }}</a>
@endforeach

```

In output I get result:

`Category1 , Category2`.

How I can remove space on the left? I need get:

`Category1, Category2`.

Answer: 
You could use [`trim()`](https://www.php.net/manual/pt_BR/function.trim.php) method or the [`str_replace()`](https://www.php.net/manual/pt_BR/function.str-replace.php) method:

```
trim($category->name);

```

or

```
str_replace(' ', '', $category->name);

```

str\_replace will replace all spaces in the string, not just the spaces in the beginning and the end of the string

trim removes the spaces just from the beginning and the end

You coud also use the [`ltrim`](https://www.php.net/manual/pt_BR/function.ltrim.php) method suggested by @devpro:

```
ltrim($category->name);

```

This will remove the spaces from the beginning of the string
It's not about trimming at all. It's about a space you put between your loop condition and tag start. So following line should fix your problem:

```
{{$loop->first ? '' : ','}}<a href="{{route('showcategory', $category)}}">{{trim($category->name)}}</a>

```