jeudi 24 mars 2016

Dependency Injection Laravel

I have a Facade Class

use App\Http\Response 

class RUser
{
    public function signup(TokenGenerator $token_generator, $data)
    {
        $response = [];
        $access_token = $token_generator->generate(32);
        dd($access_token);
        $user = User::create($data);
        $response['user_id'] = $user->_id;
        $response[''];
    }
}

Now from my UserController I am trying to use the RUser::signup() function like below

class UserController extends Controller
{
    public function store(Request $request)
    {
        $this->request = $request;
        $payload = json_decode($this->request->getContent());
        if($this->validateJson('user.create', $payload)) {
            $validator = Validator::make((array) $payload, User::$rules);
            if ($validator->fails()) {
                $messages = $validator->errors();
                return $this->sendResponse(false, $messages);
            }
            FUser::signup($payload);
            return $this->sendResponse(true, $response);
        }
    }
}

I think Laravel resolves these dependency automatically and i shound not be passing the instance of TokenGenerator explicitly. But i am getting the following error.

Argument 1 passed to App\Http\Responses\RUser::signup() must be an instance of App\Utils\TokenGenerator, instance of stdClass given, called in 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire