John Davidson

php - method not calling laravel 5.1 to laravel 8.* upgrade

0 comments
Message:


I need some clarification with dynamic controller method
i upgrading the laravel 5.1 to 8.*, all is done, but only one bug,
my url is admin/admin-profile in 5.1 is working fine, but laravel 8 is not working 404 page error is showing.
this url will call method getAdminProfile(){ } but is not calling.
if this functionality is not available in laravel 8, then how can i manage this, if single url i will create route, but my application have more than 100 url like this, so please help me to solve this...
i was check this issues by compare all file both laravel 5.1 and laravel 8
missing one file to capture the like this problem from ControllerInspector from routing folder.
so please help to solve this..
i can't write each method in web.php


Route::controller('admin', 'AdminController');

class AdminController extends BaseController {

public function getIndex()
{
//
}

public function getAdminProfile()
{
//
}

public function anyLogin()
{
//
}

}


My Answer:
In Laravel 8, the Route::controller method has been removed. You will need to define each route explicitly in your routes/web.php file.

You can achieve this by using the Route::get method for each of your controller methods. Here is an example of how you can define the routes for your AdminController in Laravel 8:

php
use App\Http\Controllers\AdminController;

Route::get('admin', [AdminController::class, 'getIndex']);
Route::get('admin/admin-profile', [AdminController::class, 'getAdminProfile']);
Route::any('admin/login', [AdminController::class, 'anyLogin']);


By defining each route explicitly like this, you can ensure that your controller methods are called correctly in Laravel 8. This approach will also make it easier to manage and maintain your routes as your application grows.

Make sure to update your controller namespace in the routes/web.php file if it is different from the example provided above.

Rate this post

5 of 5 based on 7399 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us