Php 无法在数据库Laravel 5中保存多个图像
我有一个名为“cases”的表,其中Php 无法在数据库Laravel 5中保存多个图像,php,mysql,laravel,laravel-5,Php,Mysql,Laravel,Laravel 5,我有一个名为“cases”的表,其中列是idimage1,content1,image2,content2,image3和content3 <div class="form-group"> <label>Left Image</label> <input type="file" name="leftimage">
列
是id
image1
,content1
,image2
,content2
,image
3和content3
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
当我从表单提交时,我的content1、content2、content3将保存在数据库中,但图像不会保存在文件夹中,也不会保存在数据库中。我需要帮助
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
控制器
public function store(Request $request,SidContainRequest $request)
{
$sidContain = new sidcontain;
$sidContain->content1 = $request->get('page_content1');
$sidContain->content2 = $request->get('page_content2');
$sidContain->content3 = $request->get('page_content3');
//upload multiple files
$files= [];
if($request->file('leftimage')) $files[] = $request->file('leftimage');
if($request->file('Middleimage')) $files[] = $request->fiel('Middleimage');
if($request->file('Rightimage')) $files[] = $request->file('Rightimage');
foreach($files as $flle)
{
if(!empty($file))
{
$filename[] = $file->getClientOrginalName();
if(isset($filename)){
$file->move(base_path().'/frontend/sidimage/',end($filename));
}
}
$sidContain->image1 = $filename[0];
$sidContain->image2 = $filename[1];
$sidContain->image3 = $filename[2];
}
$ok = $sidContain->save();
if($ok)
{
\Session::flash('flash_message','Report Added Successfully!');
return Redirect::to('administrator/sidConatin/create');
}
}
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
视图/表格
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
左图
@if($errors->has('leftimage')){{{$errors->first('leftimage')}
@endif
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
左内容
@如果($errors->has('page_content1')){{{$errors->first('page_content1')}
@endif
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
中间图像
@if($errors->has('Middleimage')){{{$errors->first('Middleimage')}
@endif
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
中间内容
@如果($errors->has('page_content2')){{{$errors->first('page_content2')}
@endif
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
正确形象
@如果($errors->has('Rightimage')){{{$errors->first('Rightimage')}}
@endif
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
正确内容
@如果($errors->has('page_content3')){{{$errors->first('page_content3')}
@endif
<div class="form-group">
<label>Left Image</label>
<input type="file" name="leftimage">
@if($errors->has('leftimage')) <p style="color:red;">{{$errors->first('leftimage')}}</p>@endif
</div>
<div class="form-group">
<label>Left Content</label>
<textarea name="page_content1" id="page_content1" class="editor form-control"></textarea>
@if($errors->has('page_content1'))<p style="color:red;">{{$errors->first('page_content1')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Image</label>
<input type="file" name="Middleimage">
@if($errors->has('Middleimage')) <p style="color:red;">{{$errors->first('Middleimage')}}</p>@endif
</div>
<div class="form-group">
<label>Middle Content</label>
<textarea name="page_content2" id="page_content2" class="editor form-control"></textarea>
@if($errors->has('page_content2')) <p style="color:red;">{{$errors->first('page_content2')}}</p>@endif
</div>
<div class="form-group">
<label>Right Image</label>
<input type="file" name="Rightimage">
@if($errors->has('Rightimage')) <p style="color:red;">{{$errors->first('Rightimage')}}</p>@endif
</div>
<div class="form-group">
<label>Right Content</label>
<textarea name="page_content3" id="page_content3" class="editor form-control"></textarea>
@if($errors->has('page_content3')) <p style="color:red;">{{$errors->first('page_content3')}}</p>@endif
</div>
<div style="margin-top: 15px;">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</form>
提交
您有一个输入错误:“foreach($flle文件)”应该是“foreach($file文件)”设置错误报告(E\u ALL)代码>到diplayerrors@Amarnasan你说的我听不懂,请让我说清楚,细节…@RanjeetKarki你在foreach声明中把file
这个词拼错了。它应该是文件而不是FLLE。此外,您应该从目标路径的末尾删除/
<代码>基本路径()。/frontend/sidimage'