2019-11-04 01:22:59 +01:00
< ? php
/**
2020-09-06 11:38:10 +02:00
* Invoice Ninja ( https :// invoiceninja . com ) .
2019-11-04 01:22:59 +01:00
*
* @ link https :// github . com / invoiceninja / invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @ copyright Copyright ( c ) 2024. Invoice Ninja LLC ( https :// invoiceninja . com )
2019-11-04 01:22:59 +01:00
*
2021-06-16 08:58:16 +02:00
* @ license https :// www . elastic . co / licensing / elastic - license
2019-11-04 01:22:59 +01:00
*/
namespace App\Http\Middleware ;
use Closure ;
2020-10-28 11:10:49 +01:00
use Illuminate\Http\Request ;
2019-11-04 01:22:59 +01:00
class ClientPortalEnabled
{
/**
* Handle an incoming request .
*
2020-10-28 11:10:49 +01:00
* @ param Request $request
* @ param Closure $next
2019-11-04 01:22:59 +01:00
* @ return mixed
*/
public function handle ( $request , Closure $next )
{
2023-08-07 00:23:13 +02:00
2024-06-15 08:18:33 +02:00
auth () -> guard ( 'contact' ) -> user () -> loadMissing ([ 'client' => function ( $query ) {
$query -> without ( 'gateway_tokens' , 'documents' , 'contacts.company' , 'contacts' ); // Exclude 'grandchildren' relation of 'client'
}]);
if ( auth () -> guard ( 'contact' ) -> user () -> client -> getSetting ( 'enable_client_portal' ) === false ) {
2021-05-11 03:55:47 +02:00
return redirect () -> route ( 'client.error' ) -> with ([ 'title' => ctrans ( 'texts.client_portal' ), 'notification' => 'This section of the app has been disabled by the administrator.' ]);
2019-12-30 22:59:12 +01:00
}
2019-11-04 01:22:59 +01:00
return $next ( $request );
}
}