-
app/Services/InvoiceDrafts/InvoiceDraftCollection.php
Open in GitHubuse Illuminate\Support\Collection; use Illuminate\Support\Str; class InvoiceDraftCollection { // public function __construct() { $this->session = session(); $this->instance('drafts'); } // public function get($draftKey) { $content = $this->getContent(); if (isset($content[$draftKey])) { return $content[$draftKey]; } } // public function content() { return $this->getContent(); } protected function getContent() { $content = $this->session->has($this->instance) ? $this->session->get($this->instance) : collect([]); return $content; } // }
-
app/Http/Controllers/Invoices/DraftsController.php
Open in GitHubuse App\Entities\Projects\Project; use App\Services\InvoiceDrafts\InvoiceDraftCollection; use Illuminate\Http\Request; class DraftsController extends Controller { private $draftCollection; public function __construct() { $this->draftCollection = new InvoiceDraftCollection(); } public function index(Request $request) { $draft = $this->draftCollection->content()->first(); $projects = Project::pluck('name', 'id'); return view('invoice-drafts.index', compact('draft', 'projects')); } public function show(Request $request, $draftKey = null) { $draft = $draftKey ? $this->draftCollection->get($draftKey) : $this->draftCollection->content()->first(); if (is_null($draft)) { flash(__('invoice.draft_not_found'), 'danger'); return redirect()->route('invoice-drafts.index'); } $projects = Project::pluck('name', 'id'); return view('invoice-drafts.index', compact('draft', 'projects')); } // }