app/Http/Controllers/LivreController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $dataLivre = array();
        $dataLivre['state'] = $request->input('state');
        $dataLivre['price'] = $request->input('prixDesirer');
        JWTAuth::setToken($request->input('token'));
        $token = JWTAuth::getToken();
        $credential = JWTAuth::decode($token);
        $dataStudent['email'] = $credential->get("email");
        $dataStudent['phone'] = $credential->get("phone");
        if(empty($dataStudent['email'])){
            $student = Etudiant::where('phone',$dataStudent['phone'])->first();
        }
        else{
            $student = Etudiant::where('email',$dataStudent['email'])->first();
        }
        $descriptionLivre = DescriptionLivre::firstOrNew([
            "ISBN_10"=>$request->input('ISBN_10'),
            "ISBN_13"=>$request->input('ISBN_13')
        ]);
        $descriptionLivre->price = $request->input('price');
        $descriptionLivre->pages = $request->input('pages');
        $descriptionLivre->author = $request->input('author');
        $descriptionLivre->title = $request->input('title');
        $descriptionLivre->image_link = $request->input('image_link');
        $descriptionLivre->save();
        $livre = new Livre($dataLivre);
        $livre->descriptionLivre()->associate($descriptionLivre);
        $livre->etudiant()->associate($student);
        $livre->save();
        return response()->json(['status' => 200, 'message'=>'success']);
    }
public function store ( Request $ request ) { $ dataLivre = array ( ) ; $ dataLivre [ 'state' ] = $ request -> input ( 'state' ) ; $ dataLivre [ 'price' ] = $ request -> input ( 'prixDesirer' ) ; JWTAuth :: setToken ( $ request -> input ( 'token' ) ) ; $ token = JWTAuth :: getToken ( ) ; $ credential = JWTAuth :: decode ( $ token ) ; $ dataStudent [ 'email' ] = $ credential -> get ( " email " ) ; $ dataStudent [ 'phone' ] = $ credential -> get ( " phone " ) ; if ( empty ( $ dataStudent [ 'email' ] ) ) { $ student = Etudiant :: where ( 'phone' , $ dataStudent [ 'phone' ] ) -> first ( ) ; } else { $ student = Etudiant :: where ( 'email' , $ dataStudent [ 'email' ] ) -> first ( ) ; } $ descriptionLivre = DescriptionLivre :: firstOrNew ( [ " ISBN_10 " => $ request -> input ( 'ISBN_10' ) , " ISBN_13 " => $ request -> input ( 'ISBN_13' ) ] ) ; $ descriptionLivre -> price = $ request -> input ( 'price' ) ; $ descriptionLivre -> pages = $ request -> input ( 'pages' ) ; $ descriptionLivre -> author = $ request -> input ( 'author' ) ; $ descriptionLivre -> title = $ request -> input ( 'title' ) ; $ descriptionLivre -> image_link = $ request -> input ( 'image_link' ) ; $ descriptionLivre -> save ( ) ; $ livre = new Livre ( $ dataLivre ) ; $ livre -> descriptionLivre ( ) -> associate ( $ descriptionLivre ) ; $ livre -> etudiant ( ) -> associate ( $ student ) ; $ livre -> save ( ) ; return response ( ) -> json ( [ 'status' => 200 , 'message' => 'success' ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//Go find the student with email or phone //Create association between a book and a bookdescription //Save it to the database //We search for it in the