-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0e1ddc1
Showing
151 changed files
with
32,082 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
APP_ENV=local | ||
APP_DEBUG=true | ||
APP_KEY=SomeRandomString | ||
APP_URL=http://localhost | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=homestead | ||
DB_USERNAME=homestead | ||
DB_PASSWORD=secret | ||
|
||
CACHE_DRIVER=file | ||
SESSION_DRIVER=file | ||
QUEUE_DRIVER=sync | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
REDIS_PORT=6379 | ||
|
||
MAIL_DRIVER=smtp | ||
MAIL_HOST=mailtrap.io | ||
MAIL_PORT=2525 | ||
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* text=auto | ||
*.css linguist-vendored | ||
*.scss linguist-vendored |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/vendor | ||
/node_modules | ||
/public/storage | ||
Homestead.yaml | ||
Homestead.json | ||
.env |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
class Cart | ||
{ | ||
public $items = null; | ||
public $totalQty = 0; | ||
public $totalPrice = 0; | ||
|
||
public function __construct($oldCart) | ||
{ | ||
if ($oldCart) { | ||
$this->items = $oldCart->items; | ||
$this->totalQty = $oldCart->totalQty; | ||
$this->totalPrice = $oldCart->totalPrice; | ||
} | ||
} | ||
|
||
public function add($item, $id) { | ||
$storedItem = ['qty' => 0, 'price' => $item->price, 'item' => $item]; | ||
if ($this->items) { | ||
if (array_key_exists($id, $this->items)) { | ||
$storedItem = $this->items[$id]; | ||
} | ||
} | ||
$storedItem['qty']++; | ||
$storedItem['price'] = $item->price * $storedItem['qty']; | ||
$this->items[$id] = $storedItem; | ||
$this->totalQty++; | ||
$this->totalPrice += $item->price; | ||
} | ||
|
||
public function reduceByOne($id) { | ||
$this->items[$id]['qty']--; | ||
$this->items[$id]['price'] -= $this->items[$id]['item']['price']; | ||
$this->totalQty--; | ||
$this->totalPrice -= $this->items[$id]['item']['price']; | ||
|
||
if ($this->items[$id]['qty'] <= 0) { | ||
unset($this->items[$id]); | ||
} | ||
} | ||
|
||
public function removeItem($id) { | ||
$this->totalQty -= $this->items[$id]['qty']; | ||
$this->totalPrice -= $this->items[$id]['price']; | ||
unset($this->items[$id]); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Foundation\Inspiring; | ||
|
||
class Inspire extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'inspire'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Display an inspiring quote'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Console; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | ||
|
||
class Kernel extends ConsoleKernel | ||
{ | ||
/** | ||
* The Artisan commands provided by your application. | ||
* | ||
* @var array | ||
*/ | ||
protected $commands = [ | ||
// Commands\Inspire::class, | ||
]; | ||
|
||
/** | ||
* Define the application's command schedule. | ||
* | ||
* @param \Illuminate\Console\Scheduling\Schedule $schedule | ||
* @return void | ||
*/ | ||
protected function schedule(Schedule $schedule) | ||
{ | ||
// $schedule->command('inspire') | ||
// ->hourly(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
abstract class Event | ||
{ | ||
// | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
use Illuminate\Validation\ValidationException; | ||
use Illuminate\Auth\Access\AuthorizationException; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | ||
|
||
class Handler extends ExceptionHandler | ||
{ | ||
/** | ||
* A list of the exception types that should not be reported. | ||
* | ||
* @var array | ||
*/ | ||
protected $dontReport = [ | ||
AuthorizationException::class, | ||
HttpException::class, | ||
ModelNotFoundException::class, | ||
ValidationException::class, | ||
]; | ||
|
||
/** | ||
* Report or log an exception. | ||
* | ||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. | ||
* | ||
* @param \Exception $e | ||
* @return void | ||
*/ | ||
public function report(Exception $e) | ||
{ | ||
parent::report($e); | ||
} | ||
|
||
/** | ||
* Render an exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Exception $e | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function render($request, Exception $e) | ||
{ | ||
return parent::render($request, $e); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Foundation\Bus\DispatchesJobs; | ||
use Illuminate\Routing\Controller as BaseController; | ||
use Illuminate\Foundation\Validation\ValidatesRequests; | ||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; | ||
use Illuminate\Foundation\Auth\Access\AuthorizesResources; | ||
|
||
class Controller extends BaseController | ||
{ | ||
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Cart; | ||
use App\Product; | ||
use App\Order; | ||
use Illuminate\Http\Request; | ||
|
||
use App\Http\Requests; | ||
use Session; | ||
use Auth; | ||
use Stripe\Charge; | ||
use Stripe\Stripe; | ||
|
||
class ProductController extends Controller | ||
{ | ||
public function getIndex() | ||
{ | ||
$products = Product::all(); | ||
return view('shop.index', ['products' => $products]); | ||
} | ||
|
||
public function getAddToCart(Request $request, $id) | ||
{ | ||
$product = Product::find($id); | ||
$oldCart = Session::has('cart') ? Session::get('cart') : null; | ||
$cart = new Cart($oldCart); | ||
$cart->add($product, $product->id); | ||
|
||
$request->session()->put('cart', $cart); | ||
return redirect()->route('product.index'); | ||
} | ||
|
||
public function getReduceByOne($id) { | ||
$oldCart = Session::has('cart') ? Session::get('cart') : null; | ||
$cart = new Cart($oldCart); | ||
$cart->reduceByOne($id); | ||
|
||
if (count($cart->items) > 0) { | ||
Session::put('cart', $cart); | ||
} else { | ||
Session::forget('cart'); | ||
} | ||
return redirect()->route('product.shoppingCart'); | ||
} | ||
|
||
public function getRemoveItem($id) { | ||
$oldCart = Session::has('cart') ? Session::get('cart') : null; | ||
$cart = new Cart($oldCart); | ||
$cart->removeItem($id); | ||
|
||
if (count($cart->items) > 0) { | ||
Session::put('cart', $cart); | ||
} else { | ||
Session::forget('cart'); | ||
} | ||
|
||
return redirect()->route('product.shoppingCart'); | ||
} | ||
|
||
public function getCart() | ||
{ | ||
if (!Session::has('cart')) { | ||
return view('shop.shopping-cart'); | ||
} | ||
$oldCart = Session::get('cart'); | ||
$cart = new Cart($oldCart); | ||
return view('shop.shopping-cart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]); | ||
} | ||
|
||
public function getCheckout() | ||
{ | ||
if (!Session::has('cart')) { | ||
return view('shop.shopping-cart'); | ||
} | ||
$oldCart = Session::get('cart'); | ||
$cart = new Cart($oldCart); | ||
$total = $cart->totalPrice; | ||
return view('shop.checkout', ['total' => $total]); | ||
} | ||
|
||
public function postCheckout(Request $request) | ||
{ | ||
if (!Session::has('cart')) { | ||
return redirect()->route('shop.shoppingCart'); | ||
} | ||
$oldCart = Session::get('cart'); | ||
$cart = new Cart($oldCart); | ||
|
||
Stripe::setApiKey(''); | ||
try { | ||
$charge = Charge::create(array( | ||
"amount" => $cart->totalPrice * 100, | ||
"currency" => "usd", | ||
"source" => $request->input('stripeToken'), // obtained with Stripe.js | ||
"description" => "Test Charge" | ||
)); | ||
$order = new Order(); | ||
$order->cart = serialize($cart); | ||
$order->address = $request->input('address'); | ||
$order->name = $request->input('name'); | ||
$order->payment_id = $charge->id; | ||
|
||
Auth::user()->orders()->save($order); | ||
} catch (\Exception $e) { | ||
return redirect()->route('checkout')->with('error', $e->getMessage()); | ||
} | ||
|
||
Session::forget('cart'); | ||
return redirect()->route('product.index')->with('success', 'Successfully purchased products!'); | ||
} | ||
} |
Oops, something went wrong.