Shiva Bhusal
Shiva Bhusal

Reputation: 23

Page Not Found in Laravel

Code in my Route file look like this :

Route::delete('/subtask1/delete/{{subtask}}', 'TaskController@subtaskdestroy');
    Route::get('/home', 'HomeController@index');
    Route::get('/redirect/{provider}', 'SocialAuthController@redirect');
    Route::get('/callback/{provider}', 'SocialAuthController@callback');
});

Code in view file:

<form action="/subtask1/delete/{{1}}" method="POST" style="display: inline-block;">
    {{ csrf_field() }}
    {{ method_field('DELETE') }}
    <button type="submit" id="delete-task-{{$subtask->id }}" class="btn btn-danger btn-xs">
    <i class="fa fa-btn fa-trash"></i>Delete
    </button>
</form>

And code on the Controller:

public function subtaskdestroy(Request $request, Subtask $subtask)
{
    $this->authorize('checkTaskOwner', $subtask);

    $subtask->delete();

    return redirect('/tasks');
}

With this code, I am getting an error like this:

Sorry, the page you are looking for could not be found. NotFoundHttpException in RouteCollection.php line 161:

Upvotes: 0

Views: 187

Answers (2)

smartrahat
smartrahat

Reputation: 5609

You used return redirect('/tasks'); in your controller. With this line the page will redirecte to route /tasks after successfully delete the data. Make sure you have /tasks route in your route file. Example:

 Route::get('/tasks','YourController@method');

Upvotes: 0

You mistake when defined route for delete. It should be like this:

Route::delete('/subtask1/delete/{subtask}', 'TaskController@subtaskdestroy');

But you given:

Route::delete('/subtask1/delete/{{subtask}}', 'TaskController@subtaskdestroy');

More about Route Parameters:

Laravel Route Parameters

Upvotes: 1

Related Questions