Made washing-reservations search

This commit is contained in:
2020-07-29 15:27:07 +02:00
parent 0dd262d50c
commit 4826725e07
3 changed files with 114 additions and 1 deletions
@@ -11,6 +11,7 @@ use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\WashingReservation;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class WashingReservationController extends Controller
@@ -175,5 +176,66 @@ class WashingReservationController extends Controller
return Response($output);
}
}
function search(Request $request){
if($request->ajax()){
$output = "<tr>".
"<th>Vaskemaskine</th>".
"<th>Tidspunkt</th>".
"<th>Bruger</th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/pencil.svg\" alt=\"Update\"></th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/trashcan.svg\" alt=\"Delete\"></th>".
"</tr>";
//Kan ikke søge på vaskemaskine da det er en foreign key
//filter search
if($request->isCheck === "vaskemaskine")
$users = WashingReservation::query()->where('machine_id', 'LIKE',$request->search.'%')->get();
elseif ($request->isCheck === "tidspunkt")
$users = WashingReservation::query()->where('time', 'LIKE',$request->search.'%')->get();
else
$users = WashingReservation::query()->where('time', 'LIKE',$request->search.'%')
->orWhere('machine','LIKE', $request->search.'%')
->get();
if(count($users) !== 0){
foreach ($users as $key => $user){
$output.='<tr>'.
'<td>' . WashingMachine::query()->find($user->machine_id)->name . '</td>'.
'<td>' . $user->time . '</td>'.
'<td>' . ucfirst(User::query()->find($user->user_id)->name_first) . ' ' . ucfirst(User::query()->find($user->user_id)->name_last) . '</td>'.
'<td><a href="'. route("washing-reservations.edit", [ "washing_reservation" => $user->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
'<td><form method="post" action="' .route("washing-reservations.destroy", [ "washing_reservation" => $user->id ]). '" class="w-100 nostyle">'.
csrf_field().
method_field("delete").
'<button class="w-100 nostyle" onclick="return confirm(\'Are you sure you want to delete?\');" type="submit"><img class="w-100 cursor-pointer" src="'. asset('/images/icons/trashcan-dark.svg') . '" alt="Delete"></button>'.
'</form>'.
'</td>'.
'</tr>';
}
}else{
$output.='<tr>'.
'<td>Intet match</td>'.
'<td></td>'.
'<td></td>'.
'<td></td>'.
'<td></td>'.
'</tr>';
}
return Response($output);
}
}
}