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 } }
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply