2016-06-21 75 views
0

我有我的用戶表(名稱,電子郵件,密碼等),用戶可以上傳圖片,文件或視頻。刪除文件/上傳時刪除用戶

他們的照片都存儲在特定的路徑(例如/myproject/app/public/uploads/01/picture.jpg

我想,如果由用戶上傳的文件可以在用戶的​​行被刪除被刪除。

最大的問題是,我想刪除的數據,該用戶上傳,當我做php artisan migrate:refresh --seed

我想這對遷移文件2014_..._create_users_table.php

use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

use File; 

class CreateUsersTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 

     Schema::create('users', function (Blueprint $table) { 
      $table->engine = 'InnoDB'; 
      $table->increments('id'); 
      $table->string('name'); 
      $table->string('email')->unique(); 
      $table->string('password'); 
      $table->rememberToken(); 
      $table->timestamps(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::drop('users'); 
     // Deleting ALL the data that the users have uploaded 
     $dir = public_path(). "/uploads/"; 
     File::deleteDirectory($dir, true); 
    } 
} 

但我有以下錯誤當我嘗試執行時php artisan migrate:refresh --seed

[ErrorException] 
The use statement with non-compound name 'File' has no effect 

謝謝你的幫忙!

回答

1

變化use File;use Illuminate\Support\Facades\File as File;

+0

謝謝!有效 ! ^^ – Didi