app/Http/Controllers/LivreController.php
/**
     * To confirm the book reception
     * @param Request $request
     */
To confirm the book reception
@param Request $request
To confirm the book reception @param Request $request
public function confirmBookReception(Request $request){
        $book = $request->input('data');
        $confirm = $request->input('confirm');
        $emailData = array(
            "title"=>$book['title'],
            "name"=>$book['studentName'],
            "email"=>$book['studentEmail']
        );
        if($confirm){
            $bookToUpdate = Livre::find($book['id']);
            $bookToUpdate->state = $book['state'];
            $bookToUpdate->approved = 1;
            $bookToUpdate->save();
            $studentNotification = NotificationRemise::join('etudiants','etudiants_id','=','etudiants.id')
                                        ->where("isbn",$book['ISBN_10'])
                                        ->select(
                                            'etudiants.email as email',
                                            'etudiants.name as name',
                                            'isbn'
                                            )
                                        ->get();
            foreach($studentNotification as $student){
                $emailData['email'] = $student['email'];
                $emailData['isbn'] = $student['isbn'];
                Mail::send('emails.notification', $emailData, function($message) use ($emailData)
                {
                    $message->from('no-reply@ets.arid.me');
                    $message->to($emailData['email'], $emailData['name'])->subject('Notification reception livre');
                });
            }
            Mail::send('emails.remise', $emailData, function($message) use ($emailData)
            {
                $message->from('no-reply@ets.arid.me');
                $message->to($emailData['email'], $emailData['name'])->subject('Remise livre');
            });
        }
        else{
            $bookToUpdate = Livre::find($book['id']);
            $bookToUpdate->delete();
            Mail::send('emails.remise-cancel', $emailData, function($message) use ($emailData)
            {
                $message->from('no-reply@ets.arid.me');
                $message->to($emailData['email'], $emailData['name'])->subject('Remise livre annulé');
            });
        }
    }
public function confirmBookReception ( Request $ request ) { $ book = $ request -> input ( 'data' ) ; $ confirm = $ request -> input ( 'confirm' ) ; $ emailData = array ( " title " => $ book [ 'title' ] , " name " => $ book [ 'studentName' ] , " email " => $ book [ 'studentEmail' ] ) ; if ( $ confirm ) { $ bookToUpdate = Livre :: find ( $ book [ 'id' ] ) ; $ bookToUpdate -> state = $ book [ 'state' ] ; $ bookToUpdate -> approved = 1 ; $ bookToUpdate -> save ( ) ; $ studentNotification = NotificationRemise :: join ( 'etudiants' , 'etudiants_id' , '=' , 'etudiants.id' ) -> where ( " isbn " , $ book [ 'ISBN_10' ] ) -> select ( 'etudiants.email as email' , 'etudiants.name as name' , 'isbn' ) -> get ( ) ; foreach ( $ studentNotification as $ student ) { $ emailData [ 'email' ] = $ student [ 'email' ] ; $ emailData [ 'isbn' ] = $ student [ 'isbn' ] ; Mail :: send ( 'emails.notification' , $ emailData , function ( $ message ) use ( $ emailData ) { $ message -> from ( 'no-reply@ets.arid.me' ) ; $ message -> to ( $ emailData [ 'email' ] , $ emailData [ 'name' ] ) -> subject ( 'Notification reception livre' ) ; } ) ; } Mail :: send ( 'emails.remise' , $ emailData , function ( $ message ) use ( $ emailData ) { $ message -> from ( 'no-reply@ets.arid.me' ) ; $ message -> to ( $ emailData [ 'email' ] , $ emailData [ 'name' ] ) -> subject ( 'Remise livre' ) ; } ) ; } else { $ bookToUpdate = Livre :: find ( $ book [ 'id' ] ) ; $ bookToUpdate -> delete ( ) ; Mail :: send ( 'emails.remise-cancel' , $ emailData , function ( $ message ) use ( $ emailData ) { $ message -> from ( 'no-reply@ets.arid.me' ) ; $ message -> to ( $ emailData [ 'email' ] , $ emailData [ 'name' ] ) -> subject ( 'Remise livre annulé') ; } ) ; } }
To confirm the book reception
 @param Request $request
To confirm the book reception @param Request $request
//Check if this book is waiting for a notification //For each nofitication found, we send an email //Send confirmation of reception //Send confirmation of reception