app/Http/Controllers/LeaveController.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(LeaveConfigurationRequest $request)
    {
        $start = Carbon::parse($request->startdate);
        $stop = Carbon::parse($request->enddate);
        $diffDate = $start->diffInDays($stop);
        $diffTime = $start->diffInHours($stop);
        \Log::info('*******************');
        \Log::info($diffTime);
        $leaves = new Leaves();
        $leaves->startdate = !empty($request->startdate)? $request->startdate : $request->onedate;
        $leaves->enddate = !empty($request->enddate)? $request->enddate : $request->onedate;
        $leaves->leavetype = $request->leavetype;
        $leaves->reason = $request->reason;
        $leaves->user_id = $request->user_id;
        $leaves->full_name = $request->full_name;
        if($request->onedate){
            $leaves->total = '1';
        }else{
            if($diffTime <= 4){
                $leaves->total = '0.5';
            }else{
                $leaves->total = $diffDate + 1;
            } 
        }
        $leaves->status = 'PENDING';
        $leaves->note =  !empty($request->note)?$request->note:null;
        $validated = $request->validated();
        $leaves->save();
        $users = Users::all()->where('level','=','ADMIN');
        foreach ($users as $user){
            $allmail[] = $user->email;      
        }
           Mail::to($allmail)->send(new NewLeaveRequest($leaves)); 
        return response()->json(['leaves'=> $leaves]);
    }
public function store ( LeaveConfigurationRequest $ request ) { $ start = Carbon :: parse ( $ request -> startdate ) ; $ stop = Carbon :: parse ( $ request -> enddate ) ; $ diffDate = $ start -> diffInDays ( $ stop ) ; $ diffTime = $ start -> diffInHours ( $ stop ) ; \ Log :: info ( '*******************' ) ; \ Log :: info ( $ diffTime ) ; $ leaves = new Leaves ( ) ; $ leaves -> startdate = ! empty ( $ request -> startdate ) ? $ request -> startdate : $ request -> onedate ; $ leaves -> enddate = ! empty ( $ request -> enddate ) ? $ request -> enddate : $ request -> onedate ; $ leaves -> leavetype = $ request -> leavetype ; $ leaves -> reason = $ request -> reason ; $ leaves -> user_id = $ request -> user_id ; $ leaves -> full_name = $ request -> full_name ; if ( $ request -> onedate ) { $ leaves -> total = '1' ; } else { if ( $ diffTime <= 4 ) { $ leaves -> total = '0.5' ; } else { $ leaves -> total = $ diffDate + 1 ; } } $ leaves -> status = 'PENDING' ; $ leaves -> note = ! empty ( $ request -> note ) ? $ request -> note : null ; $ validated = $ request -> validated ( ) ; $ leaves -> save ( ) ; $ users = Users :: all ( ) -> where ( 'level' , '=' , 'ADMIN' ) ; foreach ( $ users as $ user ) { $ allmail [ ] = $ user -> email ; } Mail :: to ( $ allmail ) -> send ( new NewLeaveRequest ( $ leaves ) ) ; return response ( ) -> json ( [ 'leaves' => $ leaves ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .