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.
Leave a Reply