/** @test */
 public function delete_property()
 {
     $propertyId = $this->getTestPropertyId(true);
     $this->call('DELETE', "/delete/{$propertyId}");
     $this->assertResponseOk();
     $this->seeJson();
     $this->assertFalse(Property::where('id', $propertyId)->exists());
 }
 /**
  * Display a listing of the classroom borrow.
  *
  * @param string date
  * @return Json
  */
 public function indexDatedClassroomBorrow($date_began_at, $date_ended_at)
 {
     $sample = ['p_id' => null, 'dates' => [$date_began_at, $date_ended_at], 'times' => ['00:00:00', '23:59:59'], 'LTK' => 127];
     $classroom_borrow = Property::with(['status', 'loans' => function ($query) use($sample) {
         Loan::getConflictList($sample, $query)->where('loans.status', '=', Category::getCategoryId('loan.status', 'accepted'))->join('categories as type', 'type.id', '=', 'loans.type')->join('users', 'users.id', '=', 'user_id')->select('loans.*', 'users.username', 'users.phone', 'users.email');
     }])->where('category', '=', Category::getCategoryId('property', 'classroom'))->get();
     return response()->json($classroom_borrow);
 }
 /**
  * Display a listing of the normal classroom.
  *
  * @param Request $request
  * @return
  */
 public function indexClassroom(Request $request)
 {
     // get date
     $date = $request->input('date', date('Y-m-d', time()));
     $classroom_list = Property::with(['category', 'status', 'loanClassroom' => function ($query) use($date) {
         $query->where('date_ended_at', '>=', $date);
     }])->where('category', Category::getCategoryId('property', 'classroom'))->get();
     return response()->json($classroom_list);
 }
 /** @test */
 public function update_repair()
 {
     $property = Property::find($this->getTestPropertyId(true));
     factory(Repair::class, 5)->make(['status' => Category::getCategories('repair.status', 'processing', true)])->each(function (Repair $repair) use($property) {
         $property->repairs()->save($repair);
     });
     $property->load(['repairs']);
     $this->call('PUT', '/', ['repair_list' => $property->getRelation('repairs')->pluck('id')]);
     $this->assertResponseOk();
     $this->seeJson();
     $this->assertSame(Category::getCategories('property.status', 'normal', true), Property::find($this->getTestPropertyId(true))->getAttribute('status'));
     foreach (Property::with(['repairs'])->find($this->getTestPropertyId(true))->getRelation('repairs') as $repair) {
         $this->assertSame(Category::getCategories('repair.status', 'finished', true), $repair->getAttribute('status'));
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $affect_rows = Property::where('id', '=', $id)->update(['status' => Category::getCategoryId('property.status', 'deleted')]);
     return response()->json(['status' => $affect_rows == 1 ? 0 : 2]);
 }