[英]Laravel how to get a image path?
嗨,我是Laravel的新手,我有一个带有上传文件按钮的表单,但这在我的表单上是可选的,如果我不想上传图片,则我的应用默认存储一个图片(no-image.jpg)这张图片在我的storage_path中,我如何获得该路径并将其分配给我的新记录?
我试过了,但是没有用:
if($request->infopath == null){
$request->infopath = public_path() . "/infopath"."/". 'no-image.jpg';
PreguntaAbierta::create($request->all());
Session::flash('store-success','Datos agregados correctamente!');
return redirect()->route('abierta.index');
}
'解'
我终于找到了一个解决方案,尽管这是非正统的,但却可以满足我的要求,但是我怀疑仍然是= /在我看来:
@if($pregunta->infopath == null)
<td><img src="infopath/no-image.jpg" alt="" style="width:100px"/></td>
@endif
大声笑
您可以使用->with
return redirect()->route('abierta.index')->with('infopath',$request->infopath);
并在abierta.index
其作为$ infopath abierta.index
另外,您可以在此处检查多个选项: https : //laravel.com/docs/5.1/responses
您可以这样:
$input = $request->all();
$input['infopath'] = $your_image_public_path;
PreguntaAbierta::create($input);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.