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;">