douyun3022 2016-05-12 20:38
浏览 77
已采纳

无法在Laravel5.2视图中输出图像

i'm trying to output an image inside a DIV like:

<div style="background-image:url('{{ asset($radioProg->image)}}');

Even if the img seems to be uploaded correctly in my uploads folder and i can see it on my DB, i still can not see it in my view! any help?

This is my RadioController.php

public function store(Request $request)
{
    $this->validate($request, [
        'name' => 'required',
        'day' => 'required',
        'time' => 'required',
        'intro' => 'required',
        'link_streaming' => 'required',
        'image' => 'required|image|max:2000'
        ]);

    $radioProg = new RadioProg;
    $radioProg->name = $request->name;
    $radioProg->day = $request->day;
    $radioProg->time = $request->time;
    $radioProg->intro = $request->intro;
    $radioProg->link_streaming = $request->link_streaming;

    if ($request->hasFile('image')) {
        if ($request->file('image')->isValid()) {

            $img_name = $request->file('image')->getClientOriginalName();
            $temp_file = base_path() . 'uploads/radio_programs' . $img_name;
            $radioProg->image = $request->file('image')->move('uploads/radio_programs', $img_name);
        }
    }

    $radioProg->save();

    Session::flash('success', 'Tu nuevo programa de radio ha sido guardado correctamente!');

    return redirect()->route('admin.radio.index', [$radioProg->id]);
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{
    $radioProg = RadioProg::find($id);
    return view('radio.show')->with('radioProg', $radioProg);
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{   
    $radioProg = RadioProg::find($id);
    return view('radio.edit')->with('radioProg', $radioProg);
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    $radioProg = RadioProg::find($id);
    $this->validate($request, [
        'name' => 'required',
        'day' => 'required',
        'time' => 'required',
        'intro' => 'required',
        'link_streaming' => 'required',
        'image' => 'required|image|max:2000'
        ]);

    $radioProg->name = $request->input('name');
    $radioProg->day = $request->input('day');
    $radioProg->time = $request->input('time');
    $radioProg->intro = $request->input('intro');
    $radioProg->link_streaming = $request->input('link_streaming');

    if ($request->hasFile('image')) {
        if ($request->file('image')->isValid()) {

            $img_name = $request->file('image')->getClientOriginalName();
            $temp_file = base_path() . 'uploads/radio_programs' . $img_name;
            $radioProg->image = $request->file('image')->move('uploads/radio_programs', $img_name);

        }
    }


    $radioProg->save();

    Session::flash('success', 'Tu programa de radio ha sido modificado con éxito!');

    return redirect()->route('admin.radio.index', [$radioProg->id]);

}

And this is my view:

<div class="row radio-programs">
    @foreach($radioProgs as $radioProg)
    <div class="col-md-4 {{ count($radioProgs) === 1 ? "col-md-offset-4" :""}} col-program">
        <div class="panel panel-default panel-program" style="background-image:url('{{ asset($radioProg->image)}}'); background-position: center; background-size: cover;-webkit-background-size: cover; -moz-background-size: cover;-o-background-size: cover;">
            <div class="panel-body">
                <div class="row">
                    <div class="col-md-12 col-inOverlay">
                        <h3 class="text-center"><span>{{$radioProg->name}}</span></h3>
                        <h4><span>Día: todos los {{$radioProg->day}} </span></h4>
                        <h4><span>Hora: {{$radioProg->time}} </span></h4>
                        <hr>
                        <div class="row button-program">
                            <div class="col-md-10 col-md-offset-1 col-button-program">
                                <a href="{{url('radioProgram')}}" type="button" class="btn btn-danger btn-block">Entrar</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @endforeach
</div>

in Chrome i actually see the correct path!

<div class="panel panel-default panel-program" style="background-image:url('http://localhost:8000/uploads/radio_programs\administrador_consorcio_300115.png'); background-position: center; background-size: cover;-webkit-background-size: cover; -moz-background-size: cover;-o-background-size: cover;">
  • 写回答

2条回答 默认 最新

  • duanpin2009 2016-05-13 14:50
    关注

    Not so much to answer your question, but more to debug...

    You said:

    in Chrome i actually see the correct path!

    Have you tried inspecting the element in chrome that uses the background-image style rule and seeing what image it returns? You can even open up the image in a new tab. See image:

    enter image description here

    I think it's likely the path is incorrect if you still can't see it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里