Why is this page returning in JSON?Laravel 5.2 게시물을 작성
, laravel에 내 응용 프로그램은 한 가지를 제외하고 큰 노력 상당히 새로운
내가 새 게시물을 만들 이동이 데이터베이스에 저장하지 못하고 요청 JSON 페이지를 반환합니다.
이 문제를 해결하는 데 도움을 주시면 매우 감사하겠습니다.
내가 문제가 웅변 관련이있을 수 있습니다 생각, 코드는 내가 오류를 찾을 수 없습니다 있습니다.
@extends('main')
@section('title', '| Create New Post')
@section('stylesheets')
\t {!! Html::style('css/parsley.css') !!}
\t {!! Html::style('css/select2.min.css') !!}
\t <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
\t <script>
\t \t tinymce.init({
\t \t \t selector: 'textarea',
\t \t \t plugins: 'link code',
\t \t \t menubar: false
\t \t });
\t </script>
@endsection
@section('content')
\t <div class="row">
\t \t <div class="col-md-8 col-md-offset-2">
\t \t \t <h1>Create New Post</h1>
\t \t \t <hr>
\t \t \t {!! Form::open(array('route' => 'posts.store', 'data-parsley-validate' => '')) !!}
\t \t \t \t {{ Form::label('title', 'Title:') }}
\t \t \t \t {{ Form::text('title', null, array('class' => 'form-control', 'required' => '', 'maxlength' => '255')) }}
\t \t \t \t {{ Form::label('slug', 'Slug:') }}
\t \t \t \t {{ Form::text('slug', null, array('class' => 'form-control', 'required' => '', 'minlength' => '5', 'maxlength' => '255')) }}
\t \t \t \t {{ Form::label('category_id', 'Category:') }}
\t \t \t \t <select class="form-control" name="category_id">
\t \t \t \t \t @foreach($categories as $category)
\t \t \t \t \t \t <option value='{{ $category->id }}'>{{ $category->name }}</option>
\t \t \t \t \t @endforeach
\t \t \t \t </select>
\t \t \t \t {{ Form::label('tags', 'Tags:') }}
\t \t \t \t <select class="form-control select2-multi" name="tags[]" multiple="multiple">
\t \t \t \t \t @foreach($tags as $tag)
\t \t \t \t \t \t <option value='{{ $tag->id }}'>{{ $tag->name }}</option>
\t \t \t \t \t @endforeach
\t \t \t \t </select>
\t \t \t \t {{ Form::label('body', "Post Body:") }}
\t \t \t \t {{ Form::textarea('body', null, array('class' => 'form-control')) }}
\t \t \t \t {{ Form::submit('Create Post', array('class' => 'btn btn-success btn-lg btn-block', 'style' => 'margin-top: 20px;')) }}
\t \t \t {!! Form::close() !!}
\t \t </div>
\t </div>
@endsection
@section('scripts')
\t {!! Html::script('js/parsley.min.js') !!}
\t {!! Html::script('js/select2.min.js') !!}
\t <!-- <script type="text/javascript">
\t \t $('.select2-multi').select2();
\t </script> -->
@endsection
게시물을 작성하기위한 컨트롤러 기능이 있습니다 ,
public function create()
{
$categories = Category::all();
$tags = Tag::all();
return view('posts.create')->withCategories($categories)->withTags($tags);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
dd($request);
// validate the data
$this->validate($request, array(
'title' => 'required|max:255',
'slug' => 'required|alpha_dash|min:5|max:255|unique:posts,slug',
'category_id' => 'required|integer',
'body' => 'required'
));
// store in the database
$post = new Post;
$post->title = $request->title;
$post->slug = $request->slug;
$post->category_id = $request->category_id;
$post->body = Purifier::clean($request->body);
$post->save();
$post->tags()->sync($request->tags, false);
Session::flash('success', 'The blog post was successfully save!');
return redirect()->route('posts.show', $post->id);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
둘 다 감사합니다! 내가 그걸 놓친 걸 믿을 수가 없어. 완벽하게 지금 일하고 :) – n31l
당신은 환영합니다 :) –