Laravel 5.4 目錄比對

    public function show($id)
    {
        $web = Web::find($id);

        $dt = Carbon::now();
        $timestamp = $dt->timestamp;
        $directories = File::directories('/var/www/html');

        $pattern = '/' . addcslashes($web->name, '-') . '$/';
        // $pattern = '/myci32-8$/';

        $matches = preg_grep($pattern, $directories);

        $path = '/var/www/html/' . $web->name;
        if(File::exists($path))
        {
            $check = '已經有這個目錄';
        }
        else
        {
            $check = '沒有這個目錄';
        }

        // 取得流量記錄
        $extends = Extend::where('web_id', $web->id)->get();

        return view('webs.show',
            compact('web', 'timestamp', 'directories', 'matches', 'pattern', 'path', 'check', 'extends'));
    }

結果:

時間戳記:
1498548347
系統目錄:
/var/www/html/backup
/var/www/html/tongtong
/var/www/html/myci3-1
/var/www/html/myci3-5
/var/www/html/myci3-6
/var/www/html/myci3-3
/var/www/html/myci3-2
/var/www/html/myci3-4
/var/www/html/myci3-8
/var/www/html/smws
/var/www/html/sweet_to_die

正規化條件:
/sweet_to_die$/
正規化比對結果:
有符合
array(1) {
[11]=>
string(26) “/var/www/html/sweet_to_die"
}

Path: /var/www/html/sweet_to_die
已經有這個目錄