我正在嘗試測驗檔案上傳,控制器總是null回傳$request->file('file')
這是我的測驗
test('can upload file', function () {
Storage::fake('local');
$file = UploadedFile::fake()->image('avatar.jpg');
$this->post(route('admin.ajax.files.store', [
'file' => $file
]));
Storage::disk('local')->assertExists($file->hashName());
});
然后在控制器中:
public function store(Request $request)
{
dd($request->file('file'));
}
輸出空
如果我看$request->file,我看到
array:1 [
"name" => "avatar.jpg"
]
我不確定在沒有實際上傳檔案的情況下測驗上傳檔案我做錯了什么。
uj5u.com熱心網友回復:
您需要將陣列移動到->post()
$this->post(route('admin.ajax.files.store'), [
'file' => $file
]);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/491198.html
