Esempio n. 1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(User $user)
 {
     if ($user) {
         $president = HumanResource::president();
         $positions = Position::all();
         $departments = Department::department()->get();
         $institutes = Department::institute()->get();
         return view('user.api.edit')->with(compact('user', 'president', 'positions', 'departments', 'institutes'));
     } else {
         return false;
     }
 }
 /**
  * @param Request $request
  */
 public function store(Request $request)
 {
     if ($this->validator($request->all())->fails()) {
         flash()->error('You have missing fields.');
         return redirect()->back();
     }
     $training = Training::create($request->all());
     if ($training) {
         if (is_array($request->participants)) {
             foreach ($request->input('participants') as $participant) {
                 try {
                     if ($participant == 'all') {
                         foreach (Employee::all() as $employee) {
                             TrainingParticipant::create(['training_id' => $training->id, 'employee_id' => $employee->id]);
                             // $training->employees()->attach($employee->id);
                         }
                         break;
                     } elseif (is_object(json_decode($participant))) {
                         $participant = json_decode($participant);
                         foreach (Department::find($participant->id)->users as $user) {
                             TrainingParticipant::create(['training_id' => $training->id, 'employee_id' => $user->employee->id]);
                             // $training->employees()->attach($user->employee->id);
                         }
                     } else {
                         TrainingParticipant::create(['training_id' => $training->id, 'employee_id' => $participant]);
                         // $training->employees()->attach($participant);
                     }
                 } catch (QueryException $ex) {
                 }
             }
         }
         flash()->success('Successfully added the trainings and seminar.');
     } else {
         flash()->error('Oopss! Something went wrong.');
     }
     return redirect()->back();
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, Department $department)
 {
     if ($this->validator($request->all())->fails()) {
         flash()->error('You have missing fields.');
         return redirect()->back();
     }
     $department->update($request->all());
     if ($request->employee_id != null) {
         $department_head = DepartmentHead::create(['department_id' => $department->id, 'employee_id' => $request->employee_id, 'date_from' => Carbon::today(), 'date_to' => null]);
     }
     flash()->success($department->name . ' successfully updated!');
     return redirect()->to('/departments');
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $departments = Department::department()->get();
     $institutes = Department::institute()->get();
     $positions = Position::all();
     return view('employee.index')->with(compact('departments', 'institutes', 'positions'));
 }
 public function show(Request $request, $code)
 {
     $department = Department::whereCode($code)->with('employees.user')->firstOrFail();
     return $department;
 }