mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
82 - Refactoring to a Facade
This commit is contained in:
14
app/Facades/OrderConfirmationNumber.php
Normal file
14
app/Facades/OrderConfirmationNumber.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use App\OrderConfirmationNumberGenerator;
|
||||
|
||||
class OrderConfirmationNumber extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return OrderConfirmationNumberGenerator::class;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Facades\OrderConfirmationNumber;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
@@ -11,14 +12,12 @@ class Order extends Model
|
||||
public static function forTickets($tickets, $email, $amount)
|
||||
{
|
||||
$order = self::create([
|
||||
'confirmation_number' => app(OrderConfirmationNumberGenerator::class)->generate(),
|
||||
'confirmation_number' => OrderConfirmationNumber::generate(),
|
||||
'email' => $email,
|
||||
'amount' => $amount,
|
||||
]);
|
||||
|
||||
foreach ($tickets as $ticket) {
|
||||
$order->tickets()->save($ticket);
|
||||
}
|
||||
$order->tickets()->saveMany($tickets);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace App\Providers;
|
||||
use App\Billing\PaymentGateway;
|
||||
use App\Billing\StripePaymentGateway;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\OrderConfirmationNumberGenerator;
|
||||
use App\RandomOrderConfirmationNumberGenerator;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -30,5 +32,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
});
|
||||
|
||||
$this->app->bind(PaymentGateway::class, StripePaymentGateway::class);
|
||||
$this->app->bind(OrderConfirmationNumberGenerator::class, RandomOrderConfirmationNumberGenerator::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user