jeudi 26 décembre 2019

How to retrieve multiple rows and edit specific column without saving eloquent laravel

I am planning to compare the time started_at and finished_at based on the table to determine whether there is a clash on the next booking appointment

appointment_appeal

and then I suppose to retrieve all row started_at and finished_at data and convert it into int example started_at 14:00 convert into 1400, 15:30 into 1530 then I can compare with the value that inputted next whether it clashes with the other data or not which I convert also into int like before.

here is the code that I try but I think this code is totally mess up, I just hope that you get what I mean by check this code, this code work perfectly until $test and below that are declared.

If you have any suggestions on how to write the right syntax or any better methods on how to determine clashing time then it will be appreciated and I am not that good at coding so please make it as simple as you can.

public function bookingappointment(Request $request, $name, $day) 
  {
   $_SESSION['name'] = Auth::user()->name;
   $_SESSION['role'] = AUth::user()->role;
   $available = available::where('user_name', $name)->get();
   $appeal = new appointment_appeal;
   $appeal->request_from_id = $_SESSION['name'];
   $appeal->request_to_id = $name;
   $hari = date('Y-m-d', strtotime("next $day"));
   $appeal->date = $hari;
   $appeal->started_at = $request->time1;
   $appeal->finished_at= $request->time2;
   $appeal->tittle = $request->tittle;
   $appeal->description = $request->description;
   $appeal->action = "";
   $test = appointment_appeal::all();
   $test2 = appointment_appeal::all()->count();
   for ($i = 1; $i <= $test2; $i++)
   {
    appointment_appeal::all()->update(['started_at' => 'date("Hi", strtotime('$test->started_at')')]);
   }
   $start = str_replace(':', "", $appeal->started_at);
   $finish = str_replace(':', "", $appeal->finished_at);
   switch (appointment_appeal::where('date' , '=', $appeal->date)) && (appointment_appeal::where('started_at', '>=', $start)) && (appointment_appeal::where('finished_at', '<=', $finish))->count());
   {
    case "0" :
        $ham = "no clash";
        break;
    case "1" : 
        $ham = "only 1 clash";
        break;
    case ">1" :
        $ham = "more than 1 clash";
        break;
   }
   dd($ham);
   $appeal->save();
   return view('searchedpage', ['available' => $available,
                                'namesearched' => $name,
                                'counter' => $hari,
                                'sessionname' => $_SESSION['name'],
                                'sessionrole' => $_SESSION['role']
                              ]);
  }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/35ZWNHo
via IFTTT

Aucun commentaire:

Enregistrer un commentaire