Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GodziLaravel's avatar

How to check if string is begin with "http" or not in Blade

Hello

I want to check if current variable string has "http" if not I add it .

{{$company["website"]}}
0 likes
3 replies
tykus's avatar

Global string and array helper functions are deprecated since 5.8 - but you can use the Str::startsWith() method in your Blade template

{{ Str::startsWith($company["website"], 'http') }}

You may need to add to the aliases array in config/app.php if it is not there already.

'Str' => \Illuminate\Support\Str::class,
2 likes

Please or to participate in this conversation.