Я пытаюсь сделать CRUD с несколькими загрузками изображений с laravel. Я сделал большую часть этого, но когда я попытался отправить обновление страницы обратно на страницу создания, и значение, которое я хочу ввести, пропало.
Это моя функция магазина в ArticleController
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required',
'filename' => 'required',
'filename.*' => 'image|mimes:jpeg,png,jpg,gif,svg|max:5120',
'content' => 'required'
]);
if($request->hasfile('filename'))
{
foreach($request->file('filename') as $image)
{
$name=$image->getClientOriginalName();
$image->move(public_path().'/images/', $name);
$data[] = $name;
}
}
$article= new Article();
$article->filename=json_encode($data);
$article->save();
$article = Article::create($request->all());
return redirect()->route('article.index')->with('message', 'Article Saved!');
}
и это мой create.blade.php
@extends('layouts.app')
@section('content')
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="{{ asset('js/tinymce/tinymce.min.js') }}"></script>
<script>
tinymce.init({
imageupload_url: "../upload/",
selector: "textarea",
theme: "modern",
language: "en",
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor jbimages"
],
content_css: "css/content.css",
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons jbimages",
relative_urls: false
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$(".btn-success").click(function(){
var html = $(".clone").html();
$(".increment").after(html);
});
$("body").on("click",".btn-danger",function(){
$(this).parents(".control-group").remove();
});
});
</script>
<main class="app-content">
<div class="app-title">
<div>
<h1><i class="fa fa-dashboard"></i> Artikel</h1>
<p>Berita Terbaru</p>
</div>
<ul class="app-breadcrumb breadcrumb">
<li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
<li class="breadcrumb-item"><a href="/home">Home</a></li>
</ul>
</div>
<h4>Artikel Baru</h4>
<form action="{{ route('article.store') }}" method="post">
{{csrf_field()}}
<div class="form-group {{ $errors->has('title') ? 'has-error' : '' }}">
<label for="title" class="control-label">Title</label>
<input type="text" class="form-control" name="title" placeholder="Title">
@if ($errors->has('title'))
<span class="help-block">{{ $errors->first('title') }}</span>
@endif
</div>
<form method="post" action="{{url('form')}}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="input-group control-group increment" >
<input type="file" name="filename[]" class="form-control">
<div class="input-group-btn">
<button class="btn btn-success" type="button"><i class="glyphicon glyphicon-plus"></i>Add</button>
</div>
</div>
<div class="clone hide">
<div class="control-group input-group" style="margin-top:10px">
<input type="file" name="filename[]" class="form-control">
<div class="input-group-btn">
<button class="btn btn-danger" type="button"><i class="glyphicon glyphicon-remove"></i> Remove</button>
</div>
</div>
</div>
<div class="form-group {{ $errors->has('content') ? 'has-error' : '' }}">
<label for="content" class="control-label">Content</label>
<textarea name="content" cols="30" rows="5" class="form-control"></textarea>
@if ($errors->has('content'))
<span class="help-block">{{ $errors->first('content') }}</span>
@endif
</div>
<button type="submit" class="btn btn-info">Simpan</button>
<a href="{{ route('article.index') }}" class="btn btn-default">Kembali</a>
</form>
</form>
</main>
@endsection
Спасибо за внимание