Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mikoo's avatar
Level 1

Doesnt Delete From S3

Guys my uploads to s3 work but cannot delete. Can anyone tell me what is the problem is?

    public function deleteStudentFile(Request $request)
    {
        $allowed_guards = ['managers', 'staff', 'students'];

        if (!$this->autherize($allowed_guards))
        {
            response()->json(['error' => 401], 200);
        }
        $this->user = Auth::guard($this->guard)->user();

        $file = StudentAnswerFile::where([
            ['assignment_id', '=', $request->assignment_id],
            ['student_id', '=', $this->user->id]
        ])->first();


        Storage::disk('s3')->delete($file);

        return response()->json(true, 200);
    }

PS. response is true. Thank you in advance.

0 likes
2 replies
tuneless's avatar

dd($file) dump it and it should be your path on storage as String.

I think StudentAnswerFile is a Class, ergo u get an Eloquent Collection back.

So on your model you should have a path attribute maybe......

like $file->path or so...I dunno.

rodney.hess's avatar

I hate to ask...but do you have the correct authority to delete on your S3 bucket?

Please or to participate in this conversation.