In this article, you will learn about Str::finish() in Laravel. The next question is how to incorporate Str::finish() into your project.
If a string does not already end with the given value, the Str::finish method adds a single instance of that value to it:
As an example,
use Illuminate\Support\Str; $adjusted = Str::finish('this/is/a/string', '/'); // this/is/a/string/ $adjusted = Str::finish('this/is/a/string/', '/'); // this/is/a/string/
For the first example, you can see that slash(/) is missing from the end of the string. So our cute function added it to the string.
For the second example, we already have the slash(/) at the end of the string, so there is no need to add this.
I hope you understand the differences.
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