jeudi 9 décembre 2021

Route issue in Laravel with several controllers and different route with same name

I have added below routes in web.php but it's not working.

Route::post('show', [
'as' => 'usersinformation.show',
'uses' => 'usersinformationController@show'


 ]);



 Route::post('store', [
    'as' => 'usersinformation.store',
    'uses' => 'usersinformationController@store'
  ]);



 Route::get('store',[usersController::class, 'store'])->name('usersinformation.store');
    Route::post('/store', 'usersController@store');
    Route::post('store',[usersController::class, 'store'])->name('users.store');
    Route::get('/index', 'usersController@index');

my controller is as below and I am using Ajax to send data but the error I receive is Method not allowed exception.

public function store(Request $request)
{
    //
    $fname = $request -> fname;
    $lname = $request -> lname;
    $pnumber = $request -> pnumber; 

    
}

Ajax Code ----------------

data = {
    _token: $('input#usersinformation-token').val(),
    'fname': $('input#first_name').val(), 
    'lname': $('input#last_name').val(),
    'pnumber': $('input#phonenumber').val()

};
$.post(url, data, function(data, status){
    alert('working' + data + "    " + status );
    $('div#load-content').html(data);
} );


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire