Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shoken's avatar

Form submit not working

I've been stuck with this issue for serveral hours, so hopefully some of you can help. Thanks in advance.

The issue is simple: when I click the form's submit button, nothing happens. Like, literally nothing. No errors, anything. Before starting developing the form I had created the Message model by doing

php artisan make:model Message --resource

Thus I have the methods create, store etc.. already done and ready (thanks artisan!). In my route web.php route file, I have:

Route::resource('Message','MessageController');

This should automatically link all the methods, right?

Anyway, my form is:

{!!  Form::open(['action' => 'MessageController@store', 'method' => 'POST']) !!}
                                    <ul class="row">
                                        <li class="col-sm-6">
                                            <label>{{Form::label('name','Name')}}</label>
                                                {{Form::text('name', '', ['class' => 'form-control'])}}
                                        </li>
                                        <li class="col-sm-6">
                                            <label>{{Form::label('email','Email')}}</label>
                                                {{Form::text('email', '', ['class' => 'form-control', 'placeholder' => 'Your email'])}}
                                        </li>
                                        <li class="col-sm-12">
                                            <label>{{Form::label('message','Message')}}</label>
                                                {{Form::textarea('message','', ['class' => 'form-control'])}}
                                        </li>
                                        {{Form::submit('Submit', ['class' => 'btn-round'])}}

                                    </ul>
                                    {!! Form::close() !!}

and my MessageController@store looks like this:

 public function store(Request $request)
    {
        $this -> validate($request, [
            'name' => 'required',
            'email' => 'required',
            'message' => 'required'
            ]
            );

        $message = new Message();
        $message -> name= $request -> input('name');
        $message -> email= $request -> input('email');
        $message -> text= $request ->input('text');
        $message -> user_id = Auth::user()->id;

        $message->save();

        return redirect('/');
    }

The controller just doesn't seem to work because even if I cut validation, nothing happens. I have no clue what I'm doing wrong!

0 likes
12 replies
munazzil's avatar

Try to put before the auth \ and can you dd($request) and display over here?.and where do you get this text it not have in form changed to message?

 public function store(Request $request)
    {
     dd($request);
    $this -> validate($request, [
        'name' => 'required',
        'email' => 'required',
        'message' => 'required'
        ]
        );

    $message = new Message();
    $message -> name= $request -> input('name');
    $message -> email= $request -> input('email');
    $message -> text= $request ->input('message');
    $message -> user_id = \Auth::user()->id;

    $message->save();

    return redirect('/');
    }
Shoken's avatar

@MUNAZZIL - I get nothing new. Everything's just as it was before: I think the controller is never even called.

munazzil's avatar

Can you show your web.php?

and when you use dd($request) what was the output?;

Shoken's avatar

Here is my web.php:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', 'FrontEndController@index');
Route::get('/about','FrontEndController@about');


Auth::routes();

/*
Route::get('/home', 'HomeController@index')->name('home');*/




Route::get('/admin',function (){
    return view('back_end.index');
});

Route::get('/admin',function (){
    return view('back_end.dashboard');
});


Route::get('/admin/users', 'BackendController@users');
Route::resource('Message','MessageController');

And I had no output with dd($request). Or at least, I don't know how to get it. Simply going with php artisan serve again produced nothing, and neither did clicking on the button.

munazzil's avatar

Have you called your model in controller above as like below.

use App\Message;

Can you show your message model too

munazzil's avatar

And your config/app.php change as like below.

     'debug' => env('APP_DEBUG', true),
Shoken's avatar

@MUNAZZIL - I have, that use is already in place. My message model is empty as I created that with artisan together with its migration.

However, I feel like the controller is not the issue, because even if I simply put "return 123" in the store function, it still doesn't work. I feel like the issue is in the Routing or something, but I just can't get it to work.

munazzil's avatar

That why write below code in your model and show your full controller,

                  protected $guarded = [];

with that display the output

php artisan route:list
tomopongrac's avatar
Level 51

Try to use lower case in route

Route::resource('message','MessageController');
realrandyallen's avatar

@SHOKEN - Not sure if the casing is messing it up but try:

// change
Route::resource('Message','MessageController');

// to 
Route::resource('message','MessageController');

I'd also look at/post the raw html that's being generated so we can make sure the form is being created as expected. View Source in the Browser and let's see what that plugin generated.

NoTimeForCaution's avatar

Start with a simple call to the controller via routing to check things are working:

Route::post('/model', 'ModelsController@store');

And then in ModelsController::store

dd('You have hit the endpoint')
Shoken's avatar

Thanks everyone for the answers. I've tried each and everyone of them.

I fixed it, but none of those were the answer. Turns out, I had an open tag in my HTML even before I started writing the form in Laravel. So they were kind of innested forms..? I'm not really sure, but I can see why it wasn't working.

Oh also actually I had to change the routing to lowercase message, that was also necessary.

I lost 4 hours on this. In case anyone else has this problem, please please please check your HTML.

Thanks again!

Please or to participate in this conversation.