Witam Mam problem gdyz nie moge zapisac komentarza dla danego posta i nie mmam juz pojecia co tu moze byc źle i musze poprosic was o Pomoc z Gory dziekuje
Kontroller:
public function create($post_id)
{
$post = Post::all()->find($post_id);
return view('comments.create')->with('post',$post);
}
public function store(CreateCommentRequest $request)
{
$data = $request->all();
$comment = new Comment($data);
Auth::user()->comment()->save($comment);
return redirect('/blog');
}
Widok:
@extends('base')
@section('pageContent')
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="card">
<div class="panel-body">
<!-- Formularz -->
@if(count($errors)>0)
<div class="alert alert-danger">
<ul>
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
</ul>
</div>
@endif
{!! Form::open(['url'=>"/blog/add_comment/$post->id", 'class'=>'form-horizontal']) !!}
<div class="jumbotron">
<div class="form-group">
<div class="col-md-4 control-label">
{!! Form::label('content','Zawartosc: ') !!}
</div>
<div class="col-md-6">
{!! Form::textarea('content', null,['class'=>'form-control']) !!}
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
{!! Form::submit('Zapisz',['class'=>'btn btn-primary']) !!}
</div>
</div>
<div class="form-group">
{{ Form::hidden('post_id',$post->id) }}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endsection
Web.php
Route::get('/blog/add_comment/{id}', 'CommentsController@create');
Route::post('/blog/add_comment/{id}', 'CommentsController@store');
Route::get('/blog/deleteComment/{id}', 'CommentsController@deleteComment');
Blad:
SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: comments.post_id (SQL: insert into "comments" ("content", "user_id", "updated_at", "created_at") values (dsadwdawd, 1, 2016-12-13 11:41:53, 2016-12-13 11:41:53))