In today’s tutorial, we will show you how to use string is() function Laravel. Basically, this function determines if a given string matches a given pattern. Asterisks can be used to indicate wildcards.
Note: we can use this function as Str::is() or is(), both are correct as it’s a helper function, and it can be used anywhere in the application.
Check the below example to see in action
class TestController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index() { $string1 = Str::is('tutsp*', 'tutsplanet'); dd($is1); // outputs true $string2 = Str::is('helo*', 'tutsplanet'); dd($is2); // outputs false } }
Leave a Reply