Laravel 8 dirname {#collection-method}
dirname
方法用于返回指定字符串的父级目录部分:
use Illuminate\Support\Str;
$string = Str::of('/foo/bar/baz')->dirname();
// '/foo/bar'
您亦可指定您想要从字符串中删除多少个目录级别,该参数是可选的:
use Illuminate\Support\Str;
$string = Str::of('/foo/bar/baz')->dirname(2);
// '/foo'