英文:
Class App\Http\Controllers\Api\ClientController does not exist Laravel 5.6
问题
I am trying to run an api on Postman, I am getting this error:
"ReflectionException: Class App\Http\Controllers\Api\ClientController does not exist in file /home/nosi/myProjects/paylesotho/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 752"
Below is what I did:
我的控制器(Controller):
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ClientController extends Controller
{
public function registerClient(request $request){
$merchant_code=$request->input('merchant_code');
$email_address=$request->input('email_address');
$company_name=$request->input('company_name');
$service_provider=$request->input('service_provider');
$password=$request->input('password');
$confirm_password=$request->input('confirm_password');
$client = DB::insert('insert into clients_info(id, merchant_code, email_address, company_name, service_provider, passoword, confirm_password) values(?,?,?,?,?,?,?)', [null, $merchant_code, $email_address, $company_name, $service_provider, $password, $confirm_password]);
if($client){
return redirect('clients_info')->with('status', 'Client Registered Successfully');
}
}
}
Below is my route code :
Route::post('/register','Api\ClientController@registerClient')->name('registerClient');
英文:
I am trying to run an api on postman, I am getting this error:
"ReflectionException: Class App\Http\Controllers\Api\ClientController does not exist in file /home/nosi/myProjects/paylesotho/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 752"
below is what I did:
my controller :
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ClientController extends Controller
{
public function registerClient(request $request){
$merchant_code=$request->input('merchant_code');
$email_address=$request->input('email_address');
$company_name=$request->input('company_name');
$service_provider=$request->input('service_provider');
$password=$request->input('password');
$confirm_password=$request->input('confirm_password');
$client = DB::insert('insert into clients_info(id, merchant_code, email_address, company_name, service_provider, passoword, confirm_password) values(?,?,?,?,?,?,?)', [null, $merchant_code, $email_address, $company_name, $service_provider, $password, $confirm_password]);
if($client){
return redirect('clients_info')->with('status', 'Client Registered Successfully');
}
}
}
below is my route code :
Route::post('/register','Api\ClientController@registerClient')->name('registerClient');
答案1
得分: 0
你没有提到你的控制器目录,我假设你的控制器目录是app/Http/Controller/Api,你的命名空间不正确。
命名空间必须是 namespace App\Http\Controllers\Api;
并且不要忘记导入控制器。
如果你的控制器不在 Api
目录中,你需要从你的路由中移除 /Api
。
英文:
You have not mentioned your controller directory, I am Assuming your controller directory is app/Http/Controller/Api, your namespace is incorrect.
namespace must be. namespace App\Http\Controllers\Api;
and don't forget to import controller.
If your controller is not inside Api
directory, you need to remove /Api
from Your route.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论