PHP code example of vantezzen / laravel-account-portal
1. Go to this page and download the library: Download vantezzen/laravel-account-portal library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vantezzen / laravel-account-portal example snippets
// Use Laravel's dependency injection
class MyController extends Controller {
public function index(Vantezzen\LaravelAccountPortal\LaravelAccountPortal $laravelAccountPortal) {
// ...
}
}
// ...or...
// Create manually
$laravelAccountPortal = new Vantezzen\LaravelAccountPortal\LaravelAccountPortal();
use \Vantezzen\LaravelAccountPortal\PortalStorage\SessionPortalStorage;
class MyController extends Controller {
public function index(Request $request) {
$storage = new SessionPortalStorage($request->session());
}
}
class MyController extends Controller {
// Example for a route like "/account-portal/open/{portalUserId}"
public function openPortal(Request $request, string $portalUserId, LaravelAccountPortal $laravelAccountPortal) {
$storage = new SessionPortalStorage($request->session());
$laravelAccountPortal->openPortal(
// Current session object used to store the portal information
$storage,
// Current user that wants to open the portal
$request->user(),
// User the current user wants to portal into
User::find($portalUserId)
);
}
}
class MyController extends Controller {
public function closePortal(Request $request, LaravelAccountPortal $laravelAccountPortal) {
$storage = new SessionPortalStorage($request->session());
$laravelAccountPortal->closePortal(
// Current session object used to store the portal information
$storage,
// Get the authenticatable model instance by id
fn($id) => User::find($id)
);
}
}
$storage = new SessionPortalStorage($request->session());
// True if the session has information about being in a portal
$isInPortal = $laravelAccountPortal->isInPortal($storage);
// True if a portal can be opened into the portal user
// Please note that "$portalUser" might be left as null to check generally
$canUsePortal = $laravelAccountPortal->canUsePortal($storage, $portalUser);