Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

nafiesl/free-pmo

457 stars
2 code files
View nafiesl/free-pmo on GitHub

app/Services/InvoiceDrafts/InvoiceDraftCollection.php

Open in GitHub
use 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 GitHub
use 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'));
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.