Not able to execute form

Viewed 32

I am trying to pass in data through the form but as I hit submit the page just refresh's.
I have added the protected $fillable = ['question'];
My questions database consist of $table->string('question');
My route is Route::post('/s', 'QuestionsController@questionFormStore');
This is what I get when I run dd:-

array:1 [▼
  "_token" => "nfApJgaxL06QcCUCNryfjF52x2jdzQw2VVXil8lJ"
]

I did check in my database and there was no new entry
There is no error to be seen

Here's My View:-

@extends('layouts.app')

@section('content')


<div class="card-body">
                    <form method="POST" action="/s">
                        @csrf

                        <div class="form-group row">
                            <label for="Question" class="col-md-4 col-form-label text-md-right">{{ __('Question') }}</label>

                            <div class="col-md-6">
                                <input id="Question" type="text" class="form-control @error('Question') is-invalid @enderror" Question="Question" value="{{ old('Question') }}" required autocomplete="Question" autofocus>

                                @error('Question')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>


                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Submit') }}
                                </button>
                            </div>
                        </div>

                    </form>

@endsection

Here's My Controller:-

class QuestionsController extends Controller
{

public function questionFormStore(Request $request)
    {
        $data = request()->validate([
            'question' => 'required',
        ]);

        Question::create([
            'question' => $data['question'],
        ]);
        return redirect('/');
    }
}

-ThankYou

1 Answers

Your input does not have any name, so validate method in your controller fails. So just add missing name to send form correctly.

<input id="Question" type="text" name="question" class="form-control @error('Question') is-invalid @enderror" Question="Question" value="{{ old('Question') }}" required autocomplete="Question" autofocus>

Also I do not know for what purpose is this Question="Question" but I guess this supposed to be name instead ;)

Related