app/Http/Controllers/ApplicantController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'name'  => 'max:45',
            'email'  => 'unique:applicants,email, '.$request->id. '|max:65',
            'isHired' => 'boolean'
        ]);
        if($validator->fails()) throw new ValidationException($validator);
        $applicant = Applicant::findOrFail($request->id);
        if($request->has('name')) $applicant->name = $request->name;
        if($request->has('email')) $applicant->email = $request->email;
        if($request->has('isHired')) $applicant->isHired = $request->isHired;
        $applicant->save();
        return response()->json([
            'success' => true,
            'message' => __('apiMsg.applicant_updated'),
            'data'    => new ApplicantResource($applicant)
        ]);
    }
public function update ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'name' => 'max:45' , 'email' => 'unique:applicants,email, ' . $ request -> id . '|max:65' , 'isHired' => 'boolean' ] ) ; if ( $ validator -> fails ( ) ) throw new ValidationException ( $ validator ) ; $ applicant = Applicant :: findOrFail ( $ request -> id ) ; if ( $ request -> has ( 'name' ) ) $ applicant -> name = $ request -> name ; if ( $ request -> has ( 'email' ) ) $ applicant -> email = $ request -> email ; if ( $ request -> has ( 'isHired' ) ) $ applicant -> isHired = $ request -> isHired ; $ applicant -> save ( ) ; return response ( ) -> json ( [ 'success' => true , 'message' => __ ( 'apiMsg.applicant_updated' ) , 'data' => new ApplicantResource ( $ applicant ) ] ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//validate data //throw exception if validation fails //get applicant or fail //assign data //return applicant