예제 #1
0
 /**
  * Display the specified resource.
  * GET /targets/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $statusCode = 200;
     $authId = Auth::user()->id;
     $response = Target::where(array('uid' => $authId, 'id' => $id))->first();
     return Response::json($response, $statusCode);
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  * POST /actions
  *
  * @return Response
  */
 public function store()
 {
     $response = new stdClass();
     $statusCode = 201;
     $in = Input::only('tid', 'created_at');
     $rules = array('tid' => 'required | integer');
     $vd = Validator::make($in, $rules);
     if ($vd->fails()) {
         $errs = $vd->messages();
         $statusCode = 400;
         $response = $errs->all();
     } else {
         $authId = Auth::user()->id;
         // 先檢查是否在 Target 有登記
         $uid = Target::where(array('id' => $in['tid'], 'uid' => $authId))->pluck('uid');
         // 取得使用者的教會
         $cid = UserChurch::where(array('uid' => $authId))->pluck('cid');
         if ($uid == $authId) {
             $in['uid'] = Auth::user()->id;
             $in['cid'] = $cid;
             $action = Action::create($in);
             if ($in['created_at']) {
                 $in['created_at'] = Carbon::createFromTimeStamp($in['created_at'], 'Asia/Taipei')->toDateTimeString();
                 $action->setCreatedAt($in['created_at']);
                 $action->save();
             }
         } else {
             $statusCode = 403;
         }
     }
     return Response::json($response, $statusCode);
 }