Getting images to update
Getting images to update
Yesterday I managed to save my images to the database, but now when I try to edit the image and then save it, it doesn't save. I'm not sure where I'm going wrong. All the content saves except for the image.
Here is the test.js
$(document).ready(function(){
$(".add-form").submit(function(event){
$(this).find(".testing").each(function(){
var image = [];
$(this).parent().find(".ajax-file-upload-statusbar").each(function() {
image.push($.trim($(this).find(".ajax-file-upload-filename").html()));
});
$(this).parent().find(".img-hidden").val(JSON.stringify(image));
});
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
dataType: 'json',
encode : true,
});
});
});
I'm putting my laravel code as well just in case it helps
Here is my edit.blade.php
@extends('templates::admin')
@section('content')
{{ HTML::script('js/test.js') }}
<script type="text/javascript">
var settings = {
url: '{{ asset("upload/upload.php") }}',
dragDrop:true,
multiple : false,
showFileCounter:false,
showDone: false,
fileName: "myfile",
allowedTypes:"jpg,png,gif,pdf",
returnType:"json",
showDelete:true,
}
</script>
<div class="row">
<div class="col-lg-12">
{{ Form::model($galleries, array('method' => 'PATCH', 'route' => array('admin.gallery.update', $galleries->id), 'class' => 'add-form')) }}
<div class="form">
<div>
{{ Form::label('title', 'Title') }}
</div>
<div>
{{ Form::text('title', $galleries->title, array('id' => 'title', 'class' => 'form-control')) }}
</div>
<div>
{{ Form::label('content', 'Content') }}
</div>
<div>
{{ Form::textarea('content', $galleries->content) }}
</div>
<div id="fileuploader" class="testing">Upload</div>
{{ getImages($galleries->image) }}
<script>
var uploadObj = $("#fileuploader").uploadFile(settings);
</script>
{{ Form::hidden('image', '', array('id' => 'img-add', 'class' => 'img-hidden')) }}
<div>
{{ Form::submit('Submit', array('class' => 'btn btn-default', 'role' => 'button')) }}
</div>
</div>
{{ Form::open() }}
@if($errors->any())
<ul>
{{ implode('', $errors->all('<li class="error">:message</li>')) }}
</ul>
@endif
</div>
</div>
@stop
and this is the update function in my galleryController
public function update($id)
{
$input = Input::all();
$validation = Validator::make($input, Gallery::$rules);
if($validation->fails()){
return Redirect::route('admin.gallery.edit')
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors');
}
if($validation->passes()){
$galleries = Gallery::FindOrFail($id);
$galleries->update($input);
return Redirect::route('admin.gallery.index', $id);
}
}
Topic Participants
cerberus478
jakecigar