删除用户

时间:2016-06-21 14:45:33

标签: php laravel-4 laravel-5

我有我的用户表(包括姓名,电子邮件,密码等),用户可以上传图片,文件或视频。

他们的照片存储在特定路径中(例如/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 个答案:

答案 0 :(得分:1)

use File;更改为use Illuminate\Support\Facades\File as File;