mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-15 02:53:23 +00:00
2.5 - Adding Tickets to Orders
This commit is contained in:
@@ -28,4 +28,9 @@ class Concert extends Model
|
||||
{
|
||||
return number_format($this->ticket_price / 100, 2);
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
return $this->hasMany(Order::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,13 @@ class ConcertOrdersController extends Controller
|
||||
$amount = $ticketQuantity * $concert->ticket_price;
|
||||
$token = request('payment_token');
|
||||
$this->paymentGateway->charge($amount, $token);
|
||||
|
||||
$order = $concert->orders()->create(['email' => request('email')]);
|
||||
|
||||
foreach (range(1, $ticketQuantity) as $i) {
|
||||
$order->tickets()->create([]);
|
||||
}
|
||||
|
||||
return response()->json([], 201);
|
||||
}
|
||||
}
|
||||
|
||||
15
app/Order.php
Normal file
15
app/Order.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function tickets()
|
||||
{
|
||||
return $this->hasMany(Ticket::class);
|
||||
}
|
||||
}
|
||||
10
app/Ticket.php
Normal file
10
app/Ticket.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Ticket extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
Reference in New Issue
Block a user