Skip to content
Advertisement

Route groups and form posting in laravel

I am using CoreUI and Laravel to build a project and I want to make a form on clients/addclient which will pass all the data from form to my database.

I am struggling into this part:

I have these routes on web.php:

    Route::group(['prefix' => 'clients'], function(){
    Route::get('addclient', 'ClientController@index');
    Route::post('submit','ClientController@save');
    Route::get('viewclient', function () { return view('pages.clients.viewclient'); });
    Route::get('products', function () { return view('pages.clients.products'); });
});

I have a file called addclient.blade.php with this form tag:

<form action="{{url('clients/submit')}}" method="POST">

and on ClientController I have made this function just for testing that I get the data back:

function save(Request $req){
    print_r($req->input());
}

what am I doing wrong and I dont see any results?

thanks

Advertisement

Answer

try this

Route::group(['prefix' => 'clients'], function(){
    Route::get('addclient', 'ClientController@index')->name('addclient');
    Route::post('submit','ClientController@save')->name('submit');
    Route::get('viewclient', function () { return view('pages.clients.viewclient'); });
    Route::get('products', function () { return view('pages.clients.products'); });
});

in form

<form action="{{route('clients.submit')}}" method="POST">

you can see list group route :

php artisan route:list
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement