phplaravel

Laravel Routing does not go via the Controller


I want to access my controller and show and log the test messages.

I have been trying to access my controller via a route but it doesn't seem to work. It's my first time using Laravel so I hope anyone can help I have been struggling with this problem for a couple of hours.

It hasn't been showing error messages, but I can't find any mistakes in my syntax I tried finding if there might be possible problems in my php.ini files, but I don't know.

the form

                <form method="post" action="{{ Route('saveItem') }}" accept-charset="UTF-8">
                    {{  csrf_field()  }}
                    
                    <label for="listItem">New Todo Item</label><br>
                    <input type="text" name="listItem">
                    <button type="submit">Save item</button>
                </form>

Route

Route::post('/saveItemRoute', [TodoListController::class, 'saveItem'])->name('saveItem');

Controller

class TodoListController extends Controller
{
    public function saveItem(Request $request) {
        echo("<h1>victory2</h1>");

        \Log::debug("TodoListController");
        \Log::info(json_encode($request->all()));
        
        $newListItem = new ListItem;
        $newListItem->name = $request->ListItem;
        $newListItem->is_complete = 0;
        $newListItem->save();


        return view('welcome');
    }
}

After trying again it seem like the rout doesnt function / do anything and i cant figure out why


Solution

  • I know what whent wrong after changes to routing i needed to do this line in the cmd

        php artisan route:clear
    

    the first time i tested the routing code but i did not know after changes you need to clear the route