PHP code example of chadhurin / laravel-masquerade
1. Go to this page and download the library: Download chadhurin/laravel-masquerade 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/ */
chadhurin / laravel-masquerade example snippets
Auth::user()->masquerade($other_user);
// You're now logged as the $other_user
Auth::user()->leaveMasquerade();
// You're now logged as your original user.
Route::masquerade();
/**
* @return bool
*/
public function canMasquerade(): bool
{
return $this->hasRole('super-admin');
// For example, you can check if the user has a specific role.
}
/**
* @return bool
*/
public function canBeMasqueraded():bool
{
return !$this->hasRole('super-admin')
&& $this->can_be_masqueraded;
// For example, you can check if the user has a specific role and if the user has a flag on the users table
}