Route::post('/update-client',
array(
'uses' => 'Client\API\ClientAPIController@Update',
'as' => 'apiUpdateClient',
)
);
Route::post('/delete-client',
array(
'uses' => 'Client\API\ClientAPIController@Delete',
'as' => 'apiDeleteClient',
)
);
But, these routes are not now working in Laravel 8. Below are error details
Target class [Client\API\ClientAPIController] does not exist.
It works if I write like below and got it fixed
Route::post('/update-client',
array(
'uses' => 'App\Http\Controller\Client\API\ClientAPIController@Update',
'as' => 'apiUpdateClient',
)
);
Question -
My route file contains many client routes. So, instead of appending App\Http\Controller with each route, I thought to do it like below,
use App\Http\Controllers\Client\API\ClientAPIController;
Route::post('/update-client',
array(
'uses' => [ClientAPIController::class, 'Update'],
'as' => 'apiUpdateClient',
)
);
Above code gave me error,,,
ReflectionFunction::__construct() expects parameter 1 to be string, array given
Am I using wrong syntax for uses parameter?
Just remove the uses as told in laravel documentation.
use App\Http\Controllers\Client\API\ClientAPIController;
Route::get('/users', [ClientAPIController::class, 'Update']);
refer to this documentation https://laravel.com/docs/8.x/upgrade
All of a sudden they changed the way we write laravel routes
You have the use the new way:
Route::post(
'/update-client',
[ClientAPIController::class, 'update']
)->name('apiUpdateClient');
Route::post(
'/delete-client',
[ClientAPIController::class, 'delete']
)->name('apiDeleteClient');
More info: https://laravel.com/docs/8.x/routing#named-routes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With