91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?php
|
|
|
|
use App\ParkingLot;
|
|
use Google\Cloud\Firestore\FirestoreClient;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Web Routes
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| Here is where you can register web routes for your application. These
|
|
| routes are loaded by the RouteServiceProvider within a group which
|
|
| contains the "web" middleware group. Now create something great!
|
|
|
|
|
*/
|
|
|
|
Route::get('/', function () {
|
|
return view('welcome');
|
|
});
|
|
|
|
Auth::routes();
|
|
|
|
Route::get('/home', 'HomeController@index')->name('home');
|
|
|
|
Route::get('/lot/selectstalls', function() { return view('selectstalls'); } );
|
|
|
|
Route::get('/lot/add', function() { return view('lot.add'); } );
|
|
Route::post('/lot/post', function(\Illuminate\Http\Request $request) {
|
|
/*$this->validate($request, [
|
|
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:4096',
|
|
]);*/
|
|
|
|
if ( $request->hasFile('image') ){
|
|
$img = $request->file('image');
|
|
$name = time() . '.' . $img->getClientOriginalExtension();
|
|
$destination_path = public_path('/img/references');
|
|
$img->move($destination_path, $name);
|
|
// $this->save();
|
|
|
|
$lot_object = new ParkingLot([
|
|
'firebase_id' => str_replace(' ', '-', $request->get('name')),
|
|
'stall_coordinates' => '',
|
|
'reference_image' => $name
|
|
]);
|
|
|
|
$lot_object->save();
|
|
|
|
return view('selectstalls', [ 'image_name' => $name, 'lot_id' => $lot_object->id ]);
|
|
}
|
|
});
|
|
|
|
Route::post('/lot/generate', function(\Illuminate\Http\Request $request){
|
|
$lot_object = ParkingLot::find($request->get('lotid'));
|
|
$lot_object->stall_coordinates = $request->get('coords');
|
|
$lot_object->save();
|
|
|
|
$db = new FirestoreClient();
|
|
|
|
$doc_ref = $db->collection('lots')->document($lot_object->firebase_id);
|
|
$doc_ref->set([]);
|
|
|
|
$doc_ref = $db->collection('lots')->document($lot_object->firebase_id)->collection('info')->document('lotInfo');
|
|
$doc_ref->set([
|
|
'coordinates' => $lot_object->stall_coordinates,
|
|
'lotID' => $lot_object->id,
|
|
'refImage' => $lot_object->reference_image,
|
|
'tableLayout' => '',
|
|
]);
|
|
|
|
$coords = json_decode($lot_object->stall_coordinates);
|
|
$stall_no = 1;
|
|
foreach ($coords as $coord){
|
|
$doc_ref = $db->collection('lots')->document($lot_object->firebase_id)->collection('stalls')->document('Stall-'.$stall_no);
|
|
$doc_ref->set([
|
|
'handicap' => false,
|
|
'locationX' => $coord->x,
|
|
'locationY' => $coord->y,
|
|
'open' => true,
|
|
'passID' => 0,
|
|
'width' => $coord->w,
|
|
'height' => $coord->h,
|
|
'stall' => $stall_no,
|
|
]);
|
|
|
|
$stall_no += 1;
|
|
}
|
|
|
|
|
|
|
|
echo $request->get('coords');
|
|
}); |