Created
March 27, 2023 15:46
-
-
Save susanBuck/13863063ed331163bfc25aed4865886b to your computer and use it in GitHub Desktop.
Notes for Steph
This file contains hidden or 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 Illuminate\Http\Request; | |
use Symfony\Component\Translation\Provider\NullProvider; | |
class AppController extends Controller | |
{ | |
public function index() | |
{ | |
return view('pages/index')->with([ | |
'total' => session('total', null) | |
]); | |
} | |
public function calculate(Request $request) | |
{ | |
$request->validate([ | |
'price' => 'required', | |
]); | |
$price = $request->input('price'); | |
$discount = floatval($request->input('discount'))/100; | |
$include_tax = $request->has('include_tax'); # true/false | |
$total = $price; | |
if($discount > 0) { | |
$total = $price - ($price * $discount); | |
} | |
if($include_tax) { | |
$total = $total + ($total * .0725); | |
} | |
return redirect('/')->with([ | |
'total' => $total, | |
])->withInput(); | |
} | |
} |
This file contains hidden or 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
{{-- /resources/views/books/create.blade.php --}} | |
@extends('layouts/main') | |
@section('title') | |
Discount Price Calculator | |
@endsection | |
@section('content') | |
<h1>Discount Price Calculator</h1> | |
<p>Find out what the discounted price of an item!</p> | |
<form method='POST' action='/'> | |
<div class='details'>* Required fields</div> | |
{{ csrf_field() }} | |
<label for='price'>*Price</label> | |
<input type='number' name='price' id='price' value='{{ old("price") }}'> | |
<select class="form-select form-select-lg mb-3" aria-label="Default select example" id="discount" name="discount"> | |
<option {{ old("discount") == "0" ? "selected" : "" }} value="0">*Select Discount</option> | |
<option {{ old("discount") == "10" ? "selected" : "" }} value="10">10%</option> | |
<option {{ old("discount") == "20" ? "selected" : "" }} value="20">20%</option> | |
<option {{ old("discount") == "30" ? "selected" : "" }} value="30">30%</option> | |
<option {{ old("discount") == "40" ? "selected" : "" }} value="40">40%</option> | |
<option {{ old("discount") == "50" ? "selected" : "" }} value="50">50%</option> | |
</select> | |
<fieldset> | |
<input | |
type="checkbox" | |
name="include_tax" | |
id="include_tax" | |
{{ old("include_tax") ? "checked" : "" }} | |
> | |
<label for="include_tax">Include 7.25% Sales Tax (California)</label> | |
</fieldset> | |
<button type='submit' class='btn btn-primary'>Submit</button> | |
</form> | |
@if(count($errors) > 0) | |
<ul class='alert alert-danger'> | |
@foreach ($errors->all() as $error) | |
<li>{{ $error }}</li> | |
@endforeach | |
</ul> | |
@endif | |
@if(!is_null($total)) | |
<div class='results alert alert-primary'> | |
<div> | |
Total: ${{ $total }} | |
</div> | |
</div> | |
@endif | |
@endsection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment