2016-07-08 4 views
1

안녕하세요 저는 laravel 5.2를 처음 사용하고 몇 가지 교훈을 겪었습니다.양식 모델 바인딩이 laravel에서 작동하지 않습니다. 5.2 laravelcollective를 사용합니다.

어떤 이유로 양식 모델 바인딩이 작동하지 않습니다.

{!! Form::text('title', "$post->title" ,['class'=> 'form-control']) !!} 

을 그리고 내 데이터를 보여주고있다 :이 같은 해결 방법을 사용하고 있기 때문에

{!! Form::model($post, ['method'=>'PATCH', 'action'=> ['[email protected]', $post->id]]) !!} 

나는 $post 데이터를 받았다.

컨트롤러 :

namespace App\Http\Controllers; 

use App\Post; 
use Illuminate\Http\Request; 
use App\Http\Requests; 

class PostController extends Controller{ 
    public function update(Request $request, $id){ 
     $post =Post::findOrfail($id); 
     $post->update($request->all()); 
     return redirect('/posts'); 
    } 
} 

create.blade.php보기 :

@section('content') 
<h1>Create Post</h1> 
{!! Form::open(['method'=>'POST', 'action'=>'[email protected]']) !!} 
    <!-- Title Form Input --> 
    <div class="form-group"> 
     {!! Form::label('title', 'Title:') !!} 
     {!! Form::text('title', 'null', ['class'=> 'form-control']) !!} 
    </div> 
    <!-- Form Input --> 
    <div class="form-group"> 
     {!! Form::submit('Create Post', ['class'=> 'btn-primary form-control']) !!} 
    </div> 
{!! Form::close() !!} 
@endsection 
+1

해야 우리는'laravelcollective/html' 작곡가 패키지에 대해 이야기하고 있는가? 컨트롤러 부분의 데이터를 어떻게 처리하는지 등 양식의 전체 섹션을 게시 할 수 있습니까? – phaberest

+0

당신의 feedabck에 감사드립니다. 그렇습니다. lavavelcollective/html을 사용하고 있습니다. – Richard

답변

0

좋아, posts/partials/form.blade.php 불리는 부분에 모양의 본체를 추가하려고 열린 형태 사이를 포함/모델 닫기 태그를 작성하십시오.

예 :

posts/partials/form.blade.php

<!-- Title Form Input --> 
<div class="form-group"> 
    {!! Form::label('title', 'Title:') !!} 
    {!! Form::text('title', 'null', ['class'=> 'form-control']) !!} 
</div> 
<!-- Form Input --> 
<div class="form-group"> 
    {!! Form::submit($formButtonText, ['class'=> 'btn-primary form-control']) !!} 
</div> 

posts/create.blade.php

{!! Form::open(['method'=>'POST', 'action'=>'[email protected]']) !!} 

@include('posts.partials.form', [ 
    'formSubmitButtonText' => 'Create Post' 
]) 


{!! Form::close() !!} 

posts/edit.blade.php

{!! Form::model($post, ['method'=>'PATCH', 'action'=> ['[email protected]', $post->id]]) !!} 
@include('posts.partials.form', [ 
    'formSubmitButtonText' => 'Update Post' 
]) 
{!! Form::close() !!}    
+0

감사합니다. Ruffles, 훨씬 더 깨끗한 옵션이지만 form :: model은 여전히 ​​작동하지 않습니다. null를 돌려줍니다. – Richard

+0

아직도 무엇이 잘못되었는지 전혀 모르겠습니다. 내 컴퓨터에 네이티브를 설치하거나 동일한 결과가있는 새 라 라벨로이 작업을 시도했습니다. – Richard

+0

그건 이상합니다. 귀하의 게시물 테이블에 제목이라는 필드가 있습니까? – Ruffles

2

당신은 안 귀하의 의견에 null의 값을 인용 :

{!! Form::text('title', 'null', ['class'=> 'form-control']) !!} 

{!! Form::text('title', null, ['class'=> 'form-control']) !!} 
+0

신의 축복이 당신 !! –

관련 문제