Created
January 17, 2022 08:36
-
-
Save mikestratton/2ee62f947c0c7049245bfc9211d92ff2 to your computer and use it in GitHub Desktop.
Laravel Controller
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
public function store(DefinitionsCreateRequest $request) | |
{ | |
$input = $request->all(); | |
$input['surveyor_id'] = Auth::id(); | |
$quantity = $request->input('quantity'); | |
$samples = 0; | |
if($quantity <= 999){ | |
$samples = 3; | |
} | |
elseif($quantity >= 1000 && $quantity <= 4999){ | |
$samples = 5; | |
} | |
elseif($quantity >= 5000){ | |
$samples = 7; | |
} | |
$input['samples_required'] = $samples; | |
$definition = Definition::create($input); | |
$definition_id = $definition->id; | |
// sample | |
$data = [ | |
'property_id' => $request->property_id, | |
'surveyor_id' => Auth::id(), | |
'samples_required' => $samples, | |
'definition_id' => $definition_id, | |
'description_id' => $request->description_id, | |
]; | |
$property_id = $request->property_id; | |
//does property record exist? | |
if(Sample::where('property_id', '=', $property_id)->exists()) { | |
$i = 1; | |
$j = DB::table('samples') | |
->where('property_id', '=', $property_id) | |
->max('counter'); | |
while($i <= $samples) { | |
$k = $i + $j; | |
$data['counter'] = $k; | |
Sample::create($data); | |
$i++; | |
} | |
} | |
else{ | |
$i = 1; | |
while($i <= $samples) { | |
$data['counter'] = $i; | |
Sample::create($data); | |
$i++; | |
} | |
} | |
return redirect('/surveyor/define-ha'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment