v0.10.12a - Made filter for washing machines done
This commit is contained in:
@@ -7,6 +7,8 @@ use App\WashingMachine;
|
||||
use App\WashingReservation;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use function GuzzleHttp\Promise\all;
|
||||
|
||||
class LocationController extends Controller
|
||||
{
|
||||
@@ -176,39 +178,67 @@ class LocationController extends Controller
|
||||
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/trashcan.svg\" alt=\"Delete\"></th>".
|
||||
"</tr>";
|
||||
|
||||
if($request) {
|
||||
$locations = Location::query()->orderBy('created_at', 'desc')->where('name', '=', $request->option)->get();
|
||||
//$machines = WashingMachine::query()->where('created_at', '=', $locations->created_at)->get();
|
||||
}
|
||||
elseif($request->option == "all"){
|
||||
$locations = Location::all();
|
||||
}
|
||||
if($request->option !== 'all') {
|
||||
$locations = DB::table('washing_machines')
|
||||
->join('locations', 'washing_machines.location_id','=', 'locations.id')
|
||||
->select(DB::raw('washing_machines.name as washing_name, locations.name as location_name, locations.id as id'))
|
||||
->where('locations.id', '=', $request->option)
|
||||
->get();
|
||||
|
||||
if(count($locations) !== 0){
|
||||
foreach ($locations as $key => $location){
|
||||
$output.='<tr>'.
|
||||
'<td>' . $location->washing_name . '</td>'.
|
||||
'<td>' . $location->location_name . '</td>'.
|
||||
'<td><form method="post" action="' .route("locations.destroy", [ "location" => $location->id ]). '" class="w-100 nostyle">'.
|
||||
'<td><form method="post" action="' .route("locations.edit", [ "location" => $location->id ]). '" class="w-100 nostyle">'.
|
||||
csrf_field().
|
||||
method_field("delete").
|
||||
|
||||
if(count($locations) !== 0){
|
||||
foreach ($locations as $key => $location){
|
||||
'<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>' . $location->name . '</td>'.
|
||||
'<td><p>Test data</p></td>'.
|
||||
'<td>' . $location->name . '</td>'.
|
||||
'<td><form method="post" action="' .route("locations.destroy", [ "location" => $location ]). '" class="w-100 nostyle">'.
|
||||
'<td><form method="post" action="' .route("locations.edit", [ "location" => $location ]). '" 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>'.
|
||||
'<td>Det er ikke blivet oprettet nogen vaskmaskine på denne lokation i nu</td>'.
|
||||
'<td></td>'.
|
||||
'<td></td>'.
|
||||
'<td></td>'.
|
||||
'</tr>';
|
||||
}
|
||||
}else{
|
||||
$output.='<tr>'.
|
||||
'<td>Det er ikke blivet oprettet nogen vaskmaskine på denne lokation i nu</td>'.
|
||||
'<td></td>'.
|
||||
'<td></td>'.
|
||||
'<td></td>'.
|
||||
'</tr>';
|
||||
}
|
||||
elseif($request->option === "all"){
|
||||
$machines = WashingMachine::all();
|
||||
|
||||
if(count($machines) !== 0){
|
||||
foreach($machines as $machine) {
|
||||
$output.= '<tr>'.
|
||||
'<td>'.$machine->name.'</td>'.
|
||||
'<td>'.Location::query()->where("id", "=", $machine->location_id)->first()->name.'</td>'.
|
||||
'<td><a href="'. route("washing-machines.edit", [ "washing_machine" => $machine->id]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
|
||||
'<td><form method="post" action="'. route('washing-machines.destroy', [ 'washing_machine' => $machine->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>Det er ikke blivet oprettet nogen vaskmaskine på denne lokation i nu</td>'.
|
||||
'<td></td>'.
|
||||
'<td></td>'.
|
||||
'<td></td>'.
|
||||
'</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return Response($output);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user