app/Http/Controllers/GestionnaireController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  Request  $request
     * @return Response
     */
Store a newly created resource in storage.
@param  Request  $request
@return Response
Store a newly created resource in storage . @param Request $request @return Response
public function store(Request $request)
    {
        $message = "";
        $gestionnaireData = $request->only('email', 'password');
        $coopData = $request->only('address', 'name');
        $gestionnaireData['password'] = Hash::make($gestionnaireData['password']);
        $gestionnaire = new Gestionnaire($gestionnaireData);
        $coop = new Cooperative($coopData);
        $coop->save();
        $gestionnaire->cooperative()->associate($coop);
        $gestionnaire->save();
        $message = "success";
        return response()->json(['status' => 200, 'message' => $message]);
    }
public function store ( Request $ request ) { $ message = " " ; $ gestionnaireData = $ request -> only ( 'email' , 'password' ) ; $ coopData = $ request -> only ( 'address' , 'name' ) ; $ gestionnaireData [ 'password' ] = Hash :: make ( $ gestionnaireData [ 'password' ] ) ; $ gestionnaire = new Gestionnaire ( $ gestionnaireData ) ; $ coop = new Cooperative ( $ coopData ) ; $ coop -> save ( ) ; $ gestionnaire -> cooperative ( ) -> associate ( $ coop ) ; $ gestionnaire -> save ( ) ; $ message = " success " ; return response ( ) -> json ( [ 'status' => 200 , 'message' => $ message ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// Takes the request data and form an array // Hash the password //Create a new gestionnaire from the data (mass assignment) //Create association between a gestionnaire and a cooperative //Save it to the database