incorporeal
incorporeal

Reputation: 177

Laravel: Calling to post method function from the same controller in route

I have three functions in my controller.One of them is GET type and other two is POST type. One POST type is working well but how can i call the second POST method from Route?

i am calling my functions from route like this and they are working well

Route::get('/conference/home', 'ViewController@index');
Route::post('/conference/home','ViewController@showBooking');

there is another function for Deleting from database which is a post method type. Say the Name of that Function is DeletingRecord(). How can i call this function from Route?

Upvotes: 1

Views: 2957

Answers (3)

Jigneshsinh Rathod
Jigneshsinh Rathod

Reputation: 1028

why you don't use single routing line instead of more routing line as following:

Route::resource('conference', 'ViewController');

for reference please see following link:

https://laravel.com/docs/5.3/controllers#resource-controllers

i hope its help you

Upvotes: 0

Vitaliy Ryaboy
Vitaliy Ryaboy

Reputation: 478

You can use delete HTTP verb.

then your code will look like this:

Route::get('/conference/home', 'ViewController@index');
Route::post('/conference/home','ViewController@showBooking');
Route::delete('/conference/home','ViewController@DeletingRecord');

Upvotes: 2

apokryfos
apokryfos

Reputation: 40653

Some considerations:

  1. A controller method is not inherently a POST or GET method. It's the router that decides how to handle a POST or GET request.

  2. If you must use a POST request to delete a record then you must assign it to a different route name. Each route will resolve to exactly one method. For example:

    Route::get('/conference/home', 'ViewController@index');
    Route::post('/conference/home','ViewController@showBooking');
    Route::post('/conference/delete','ViewController@DeletingRecord');
    
  3. There's no reason why you can't use the DELETE method for this:

    Route::get('/conference/home', 'ViewController@index');
    Route::post('/conference/home','ViewController@showBooking');
    Route::delete('/conference/home','ViewController@DeletingRecord');
    

Upvotes: 4

Related Questions