Home>

The input contents are not reflected in the database as intended.

Error message

How the database looks
I want to insert "1" into the proof column when submitting in the form,
It will be NULL.

Because values ​​other than proof are reflected,
Probably, for $request sent in form,
It is assumed that only proof data is not sent.

Applicable source code

content.blade.php

@ extends ('layouts.top')
@section ('title', 'Anything Teacher')
@section ('content')

              ~ Omitted ~
        @if ($proof == 1)
           <form method = "POST" action = "{{action ('Student \ StudentController @ store2')}}">
            @csrf
            <input name = "proof" type = "hidden" value = "1">
    @Else
           <form method = "POST" action = "{{action ('Student \ StudentController @ store')}}">
            @csrf
        @endif

            <input name = "question_id" type = "hidden" value = "{{$question->id}}">
            <input name = "name" type = "hidden" value = "{{$teacher->name}}">
            
                <hr>
                <label for = "body">Body</label>
                <textarea name = "body" rows = "4">{{old ('body')}}</textarea>
                @if ($errors->has ('body'))
                
                    {{$errors->first ('body')}}
                
                @endif
            
            
                <button type = "submit">
                    To comment
                </button>
            
        </form>
@endsection

Controller

<? php
namespace App \ Http \ Controllers \ Student;
use App \ Http \ Controllers \ Controller;
use Illuminate \ Http \ Request;
use App \ User;
use App \ Question;
use App \ Comment;

class StudentController extends Controller
{
   ~ Omitted ~
    public function store2 (Request $request)
    {
        $params = $request->validate ([
            'question_id' =>'required | exists: questions, id',
            'body' =>'required | max: 2000',
            'proof' =>'required',
        ]);
        $question = Question :: findOrFail ($params ['question_id']);
        $question->comments ()->create ($params);
        $name = $request->name;
        $teacher = User :: where ('name', $name)->first ();
        return view ('student.content', ['teacher' =>$teacher, 'question' =>$question, 'proof' =>1]);
    }
}

If the default value of proof is changed from NULL to none in the database settings,
The following errors are possible:
Error screen