2016-08-20 5 views
0

Why is this page returning in JSON?Laravel 5.2 게시물을 작성

JSON : enter image description here

, 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 
*/ 

답변

1

위와 같이 위의 dd ($ request)가 요청한 JSON 값을 반환합니다. 양식의 모든 값이 전달되었는지 여부를 확인하는 데 처음 사용해야합니다. 테스트를 생략하고 생략해야합니다. 목적 만.

+0

둘 다 감사합니다! 내가 그걸 놓친 걸 믿을 수가 없어. 완벽하게 지금 일하고 :) – n31l

+0

당신은 환영합니다 :) –

1

먼저 할 일은 당신의 store() 운전 방식 d는 다음 중 하나입니다. dd($request).

dd()은 "덤프 및 죽기"의 약자로 전달되는 모든 내용을 덤프 한 다음 die()을 호출합니다. 보고있는 출력은 $request 변수의 덤프이며 스크립트가 종료됩니다.