mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Facades\OrderConfirmationNumber;
|
|
|
|
class Order extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
public static function forTickets($tickets, $email, $charge)
|
|
{
|
|
$order = self::create([
|
|
'confirmation_number' => OrderConfirmationNumber::generate(),
|
|
'email' => $email,
|
|
'amount' => $charge->amount(),
|
|
'card_last_four' => $charge->cardLastFour(),
|
|
]);
|
|
|
|
$order->tickets()->saveMany($tickets);
|
|
|
|
return $order;
|
|
}
|
|
|
|
public static function findByConfirmationNumber($confirmationNumber)
|
|
{
|
|
return self::where('confirmation_number', $confirmationNumber)->firstOrFail();
|
|
}
|
|
|
|
public function concert()
|
|
{
|
|
return $this->belongsTo(Concert::class);
|
|
}
|
|
|
|
public function tickets()
|
|
{
|
|
return $this->hasMany(Ticket::class);
|
|
}
|
|
|
|
public function ticketQuantity()
|
|
{
|
|
return $this->tickets()->count();
|
|
}
|
|
|
|
public function toArray()
|
|
{
|
|
return [
|
|
'confirmation_number' => $this->confirmation_number,
|
|
'email' => $this->email,
|
|
'ticket_quantity' => $this->ticketQuantity(),
|
|
'amount' => $this->amount,
|
|
];
|
|
}
|
|
}
|