Skip to content

Instantly share code, notes, and snippets.

@adamwathan
Created June 19, 2017 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamwathan/b951adfafd805be77da1a5a76d437008 to your computer and use it in GitHub Desktop.
Save adamwathan/b951adfafd805be77da1a5a76d437008 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Purchase;
use Illuminate\Support\Facades\Auth;
class OrdersController extends Controller
{
// ...
public function show($id)
{
$purchase = Auth::user()->purchases()->with('latestFulfillmentAttempts')->findOrFail($id);
return view('orders.show', [
'purchase' => $purchase,
'fulfillmentAttempts' => $purchase->latestFulfillmentAttempts,
]);
}
}
<?php
namespace App;
use App\Events\FulfillmentFailed;
use Facades\App\CreditCardGateway;
use Facades\App\WebhookDispatcher;
use Illuminate\Database\Eloquent\Model;
use App\Exceptions\WebhookFailedException;
class Purchase extends Model
{
// ...
public function fulfillmentAttempts()
{
return $this->hasMany(FulfillmentAttempt::class);
}
public function latestFulfillmentAttempts()
{
return $this->fulfillmentAttempts()->latest();
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment