osb/app/Http/Controllers/HomeController.php

94 lines
2.1 KiB
PHP
Raw Normal View History

2018-05-20 12:53:14 +00:00
<?php
namespace App\Http\Controllers;
2020-05-25 07:45:17 +00:00
use Clarkeash\Doorman\Exceptions\{DoormanException,ExpiredInviteCode};
use Clarkeash\Doorman\Facades\Doorman;
use Illuminate\Contracts\View\Factory;
2018-07-13 04:53:44 +00:00
use Illuminate\Support\Facades\Auth;
2020-05-25 07:45:17 +00:00
use Illuminate\Support\Facades\Log;
2020-02-05 04:47:24 +00:00
use Illuminate\View\View;
2019-07-02 05:28:27 +00:00
2021-06-29 03:18:52 +00:00
use App\Models\{Invoice,Service,User};
2018-07-13 04:53:44 +00:00
2021-06-29 03:18:52 +00:00
/**
* Class HomeController
* This controller is the logged in users home page
*
* The methods to this controller should be projected by the route
*
* @package App\Http\Controllers
*/
2021-06-29 00:37:24 +00:00
class HomeController extends Controller
2018-05-20 12:53:14 +00:00
{
2020-02-05 04:47:24 +00:00
/**
* Logged in users home page
*
* @return Factory|View
2020-02-05 04:47:24 +00:00
*/
2021-06-29 03:18:52 +00:00
public function home(User $o): View
2018-05-20 12:53:14 +00:00
{
if (! $o->exists)
$o = Auth::user();
2018-07-13 04:53:44 +00:00
2022-06-14 06:51:18 +00:00
$o->load(['services.invoice_items','services.type']);
return View('u.home',['o'=>$o]);
2018-05-20 12:53:14 +00:00
}
2018-07-16 05:06:43 +00:00
2020-05-25 07:45:17 +00:00
/**
* Enable the user to down an invoice by providing a link in email
*
* @param Invoice $o
* @param string $code
* @return \Illuminate\Http\RedirectResponse|mixed
*/
public function invoice_pdf_email(Invoice $o,string $code)
{
try {
Doorman::redeem($code,$o->account->user->email);
} catch (ExpiredInviteCode $e) {
Log::alert(sprintf('User is using an expired token for invoice [%s] using [%s]',$o->id,$code));
return redirect()->to('/login');
} catch (DoormanException $e) {
Log::alert(sprintf('An attempt to read invoice id [%s] using [%s]',$o->id,$code));
abort(404);
}
return $this->invoice($o);
2020-05-25 07:45:17 +00:00
}
2020-02-05 04:47:24 +00:00
/**
* Return details on the users service
*
* @param Service $o
* @return View
*/
public function service(Service $o): View
2018-08-23 05:17:26 +00:00
{
2021-12-20 04:06:01 +00:00
$breadcrumb = collect();
$breadcrumb->put($o->account->user->full_name,url('u/home',$o->account->user_id));
2021-12-20 04:06:01 +00:00
return View('u.service.home')
->with('breadcrumb',$breadcrumb)
->with('o',$o);
2020-04-18 22:33:41 +00:00
}
/**
* Progress the order to the next stage
*
* @note: Route Middleware protects this path
* @param Service $o
* @param string $status
* @return \Illuminate\Http\RedirectResponse
* @deprecated
2020-04-18 22:33:41 +00:00
*/
public function service_progress(Service $o,string $status)
{
return redirect()->to($o->action($status) ?: url('u/service',$o->id));
2018-08-01 07:09:38 +00:00
}
2018-05-20 12:53:14 +00:00
}