当我死/转储 $files 时,当我期望看到所有选定的文件时,我只能看到请求中的一个文件。当我在 foreach 循环中死亡/转储 $name 时,什么也没有发生。我需要查看请求中所有选定的图像。
刀片创建
<form action="/p" enctype="multipart/form-data" method="post" files = "true">
@csrf
<label for="image" class="col-md-4 col-form-label text-md-right">{{ __(' post image') }}</label>
<input type="file", class="form-control-file" id ="image" multiple = "multiple" name="image">
@error('image')
<div class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong> </div>
@enderror
</form>
后置控制器
public function store( Request $request )
{` $request->request->add(['user_id' => $user], ); // Here a request is given a varible either for the admin or user
$data = request()->validate([
'user_id' => 'required',
'about' => 'required',
'category' => '',
'expire_date' => '',
]); `if (Auth::guard('web')->check())
{
$user = Auth::user();
$post = new Post();
/*$post = $user->posts()->create([
'about' => $data['about'],
'category' => $data['category'],
'expire_date' => $data['expire_date'],
]);*/
if($request->hasFile('image'))
{
$files = $request->file('image');
foreach($files as $file)
{
$name = time().'-'.$file->getClientOriginalName();
$name = str_replace('','-',$name);
$file->move('images',$name);
//$post->images->create(['image' => $name ]);
}
} `
$user = Auth::guard('web')->id() ;
// return redirect()->route('home',['user'=>$user]);
}
}
交互式爱情
慕哥9229398