Created
May 30, 2019 21:00
-
-
Save mikestratton/2735982156d2b58680ff01ef960f7817 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Floor; | |
use App\Location; | |
use App\Photo; | |
use App\Property; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Support\Facades\Storage; | |
use Illuminate\Support\Facades\Response; | |
class AdminFloorsController extends Controller | |
{ | |
/** | |
* Display a listing of the resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function index() | |
{ | |
$floors = Floor::all(); | |
return view('surveyor.floor-plans.index', compact('floors')); | |
} | |
/** | |
* Show the form for creating a new resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function create() | |
{ | |
return view('surveyor.floor-plans.create'); | |
} | |
/** | |
* Store a newly created resource in storage. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return \Illuminate\Http\Response | |
*/ | |
public function store(Request $request) | |
{ | |
// | |
} | |
/** | |
* Display the specified resource. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function show($id) | |
{ | |
// | |
} | |
/** | |
* Show the form for editing the specified resource. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function edit($id) | |
{ | |
$floor = Floor::findOrFail($id); | |
$locations = Location::pluck('name', 'id')->all(); | |
$select_property = Property::pluck('address', 'id')->all(); | |
$properties = Property::all(); | |
$sketch = 'floor-example.png'; | |
foreach($properties as $property){ | |
if($floor->property_id == $property->id && | |
$property->photo->type_id == 1) | |
{ | |
$sketch = $property->photo->file; | |
} | |
} | |
return view('surveyor.floor-plans.edit', | |
compact('floor', 'properties', 'sketch', 'select_property', 'locations')); | |
} | |
/** | |
* Update the specified resource in storage. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function update(Request $request, $id) | |
{ | |
$input = $request->all(); | |
$floor = Floor::findOrFail($id); | |
$screen = $request->input('photo_url'); | |
$filterd_data = substr($screen, strpos($screen, ",")+1); | |
//Decode the string | |
$unencoded_data=base64_decode($filterd_data); | |
$name = 'screen'.time().'.png'; | |
Storage::disk('uploads')->put('uploads/'.$name, $unencoded_data); | |
$photo = Photo::create( | |
[ | |
'user_id' => Auth::id(), | |
'file' => $name, | |
'type_id' => 3, | |
'caption' => 'no caption', | |
'room_id' => null, | |
'property_id' => $floor->property_id, | |
] | |
); | |
$input['photo_id'] = $photo->id; | |
$windows = implode(',', $request->input('window')); | |
$input['windows'] = $windows; | |
if($request->input('wall')){ | |
$wall_checkbox = implode(',', $request->input('wall')); | |
$input['wall'] = $wall_checkbox; | |
} | |
if($request->input('ceil')){ | |
$ceil_checkbox = implode(',', $request->input('ceil')); | |
$input['ceiling'] = $ceil_checkbox; | |
} | |
if($request->input('floor')){ | |
$floor_checkbox = implode(',', $request->input('floor')); | |
$input['floor'] = $floor_checkbox; | |
} | |
if($request->input('heat')){ | |
$heat_checkbox = implode(',', $request->input('heat')); | |
$input['heat'] = $heat_checkbox; | |
} | |
$insul_ceil = $request->input('insul_ceil'); | |
$input['insul_ceil'] = $insul_ceil; | |
$insul_wall = $request->input('insul_wall'); | |
$input['insul_wall'] = $insul_wall; | |
// | |
// $input['insul_wall'] = $request->input('insul_wall'); | |
$floor->update($input); | |
return redirect('/floor-plans'); | |
} | |
/** | |
* Remove the specified resource from storage. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function destroy($id) | |
{ | |
// | |
} | |
public function screenshot(Request $request, $id) { | |
$input = $request->all(); | |
$floor = Floor::findOrFail($id); | |
$screen = $request->input('photo_url'); | |
$filterd_data = substr($screen, strpos($screen, ",")+1); | |
//Decode the string | |
$unencoded_data=base64_decode($filterd_data); | |
$name = 'screen'.time().'.png'; | |
Storage::disk('uploads')->put('uploads/'.$name, $unencoded_data); | |
Photo::create( | |
[ | |
'user_id' => Auth::id(), | |
'file' => $name, | |
'type_id' => 3, | |
'caption' => 'no caption', | |
'room_id' => null, | |
'property_id' => null, | |
] | |
); | |
$floor->update($input); | |
return redirect()->back(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment