How do I display the file or images in my project. I have this code in uploading the file.
public function upload(Request $request)
{
$expense = new expenses;
$expense->title = Input::get('name');
if (Input::hasFile('image')){
$expense=Input::expense('image');
$expense->move(public_path(). '/', $file->getClientOriginalName());
$expense->name = $file->getClientOriginalName();
}
$expenses->save();
return 'data save in the database';
}
This is my code in Create blade..
<div class="row">
<div class="col-xs-12 form-group">
{!! Form::label('image', 'Photo:') !!}
<form action="upload" id="upload" enctype="multipart/form-data">
<input type="file" name="image[]" id="image" multiple><br />
<p class="help-block"></p>
@if($errors->has('image'))
<p class="help-block">
{{ $errors->first('image') }}
</p>
@endif
</div>
</div>
In my index blade, showing the file I uploaded..
<tbody>
@if (count($expenses) > 0)
@foreach ($expenses as $expense)
<td><img src="/image/{{ $expense }}" style="width:150px; height:150px;"></td>
@endforeach
</tbody>
How do I display my file or images in my table, what code do I need to complete it. This code above I just follow the tutorials given to me.
First of all you will need to close off your form:
<form action="..">
...
</form>
Secondly, you are requesting an input you don't have here:
$expense->title = Input::get('name');
Thirdly, you are trying to save a variable that doesn't exist:
$expenses->save();
should it be:
$expense->save()?
there is still another error where you are calling:
<td><img src="/image/{{ $expense }}"
hope this helps for now