i have postqs table and reply table. postqs_id is foriegn key in reply table. why im i getting this error?and how to solve it
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'postqs_id' cannot be null (SQL: insert into
reply_qs
(reply
,postqs_id
,updated_at
,created_at
) values (kk, , 2017-10-27 13:54:03, 2017-10-27 13:54:03))
Controller:
public function store(Request $request)
{
$reply = new Reply_qs();
$reply->reply = $request->get('reply');
$reply->postqs_id = $request->get('postqs_id');
$postqs=$reply->postqs()->get();
$reply->save();
return redirect()->route('postqs.show')
->with('success','Your question created successfully');
}
postqs Model:
public function reply_qs(){
return $this->hasMany('App\Reply_qs');
}
reply_qs Model:
public function postqs(){
return $this->belongsTo('App\Postqs', 'postqs_id', 'id');
}
migration:
Schema::create('reply_qs', function (Blueprint $table) {
$table->increments('id')->unique();
$table->text('reply');
$table->timestamps('date');
$table->integer('postqs_id')->unsigned();
$table->foreign('postqs_id')->references('id')->on('postqs') -
>onDelete('cascade')->onUpdate('cascade');
});
blade file:
<form action="{{ route('postqs.store') }}" method="POST" class="form-
horizontal">
{{ csrf_field() }}
<div class="form-group">
<label class="control-label col-sm-2" >Reply:</label>
<div class="col-sm-7">
<textarea name="reply" id="reply" class="form-control"></textarea>
</div>
</div>
<input type="submit" class="btn btn-primary" value="Submit" >
$request->get('postqs_id');
is returningnull
. – Jackowskiform
? Show the code please. – Jackowskiname="postqs_id"
? – ljubadr