/**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(CreateAttemptRequest $request, $mission_id)
 {
     $user = User::findOrFail(1);
     $mission = Mission::findOrFail($mission_id);
     $attempt = new Attempt($request->all());
     $attempt->user()->associate($request->user());
     $attempt->mission_id = $mission_id;
     $attempt->save();
     return redirect()->route('missions.show', $mission_id);
 }
Beispiel #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $rules = array('status' => 'exists:missions,status');
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return Response::json($validator->messages(), 500);
     } else {
         $mission = Mission::findOrNew($id);
         if ($request->title) {
             $mission->title = $request->title;
         }
         $mission->status = $request->status;
         $mission->save();
         if ($mission->status == 'completed' or $mission->status == 'canceled') {
             //Free employees if mission canceling or completed
             $mission->employees()->update(['mission_id' => null]);
         }
         return Response::json($mission);
     }
 }
Beispiel #3
0
 /**
  * Put existing employee to mission and return it.
  *
  * @param  Request  $request
  * @return Response
  */
 public function putMissionEmployee($mid, $eid)
 {
     $employee = Employee::findOrNew($eid);
     $rules = array('name' => 'required', 'position' => 'required');
     $validator = Validator::make($employee->toArray(), $rules);
     if ($validator->fails()) {
         return Response::json($validator->messages(), 500);
     } else {
         $mission = Mission::findOrNew($mid);
         $mission->employees()->save($employee);
         return Response::json($employee);
     }
 }
Beispiel #4
0
 protected function isAllTargetsAchieved(Mission $mission)
 {
     $targets = $mission->targets()->get();
     $achieved_targets_count = $targets->filter(function ($item) {
         return $item->status == 'achieved';
     })->count();
     $all_targets_count = $targets->count();
     return $achieved_targets_count == $all_targets_count;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(UpdateMissionRequest $request, $id)
 {
     $mission = Mission::findOrFail($id);
     $mission->fill($request->all());
     $mission->save();
     return redirect()->route('missions.show', $id)->with('status.success', 'Success! Your mission is now updated!');
 }
Beispiel #6
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('home.index');
});
Route::get('/tasks', function () {
    return json_encode(\App\Mission::all());
});