我使用 3 个数组存储在表课程中。请帮助我将数组保存在字符串中或将数组保存在数据库中......我的数组问题:
我无法在数据库中存储和保存图像
我无法在数据库中保存数组结果和要求
<div class="col-md-10"><input type="file" class="form-control" name="images" id="images" ></div>
//and this
<input type="text" class="form-control" name="outcomes[]" id="outcomes">
//or this
<input type="text" class="form-control" name="requirements[]" id="requirements">
我的商店函数调用:
public function store(CourseRequest $request)
{
$imageUrl = $this->upload2Images($request->file('images'));
auth()->user()->course()->create(
$request->except(['_token','files']),
['images'=>$imageUrl]);
return redirect(route('courses.index'));
}
并且upload2Images()
是
public function upload2Images($file)
{
$year = Carbon::now()->year;
$month = Carbon::now()->month;
$imagePath = "upload/images/{$year}/{$month}/";
$filename = $file->getClientOriginalName();
$file = $file->move(public_path($imagePath), $filename);
$url['images'] = "upload/images/{$year}/{$month}/$filename";
return $url;
}
当我使用
$data = array_merge(
$request->except(['_token','files','outcomes','requirements']),
$images
);
$id = auth()->user()->course()->create($data)->id;
它工作正常,但结果和要求是我以这种方式隐藏的数组。我可以通过这个论点吗?