Class App\Http\Controllers\Api\ClientController does not exist Laravel 5.6

huangapple go评论62阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月7日 19:48:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193737.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定