PHP code example of andrewdwallo / filament-companies
1. Go to this page and download the library: Download andrewdwallo/filament-companies 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/ */
andrewdwallo / filament-companies example snippets
use Wallo\FilamentCompanies\Pages\User\PersonalAccessTokens;
use Wallo\FilamentCompanies\Pages\User\Profile;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->pages([
Profile::class,
PersonalAccessTokens::class,
])
}
use Filament\Navigation\MenuItem;
use Filament\Navigation\NavigationItem;
use Illuminate\Support\Facades\Auth;
use Wallo\FilamentCompanies\Pages\User\PersonalAccessTokens;
use Wallo\FilamentCompanies\Pages\User\Profile;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->userMenuItems([
'profile' => MenuItem::make()
->label('Profile')
->icon('heroicon-o-user-circle')
->url(static fn () => url(Profile::getUrl())),
MenuItem::make()
->label('Company')
->icon('heroicon-o-building-office')
->url(static fn () => url(Pages\Dashboard::getUrl(panel: 'company', tenant: Auth::user()->personalCompany()))),
])
->navigationItems([
NavigationItem::make('Personal Access Tokens')
->label(static fn (): string => __('filament-companies::default.navigation.links.tokens'))
->icon('heroicon-o-key')
->url(static fn () => url(PersonalAccessTokens::getUrl())),
])
}
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;
class FilamentCompaniesServiceProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
FilamentCompanies::make()
->userPanel('user')
)
}
}
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;
class FilamentCompaniesServiceProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
FilamentCompanies::make()
->switchCurrentCompany()
);
}
}
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;
class FilamentCompaniesServiceProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
FilamentCompanies::make()
->updateProfileInformation() // Enables updating profile information
->updatePasswords() // Enables password updates
->setPasswords() // Enables setting passwords only if Socialite is enabled
->connectedAccounts() // Enables connected account management only if Socialite is enabled
->manageBrowserSessions() // Enables browser session management
->accountDeletion() // Enables account deletion
);
}
}
use App\Livewire\CustomComponent;
FilamentCompanies::make()
->updateProfileInformation(component: CustomComponent::class);
use App\Livewire\CustomComponent;
FilamentCompanies::make()
->addProfileComponents([
7 => CustomComponent::class,
]);
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;
class FilamentCompaniesServiceProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
FilamentCompanies::make()
->profilePhotos()
)
}
}
namespace App\Actions\FilamentCompanies;
use App\Models\User;
use Filament\Notifications\Notification;
use Wallo\FilamentCompanies\Contracts\UpdatesUserPasswords;
class UpdateUserPassword implements UpdatesUserPasswords
{
/**
* Validate and update the user's password.
*
* @param array<string, string> $input
*/
public function update(User $user, array $input): void
{
// ...
}
public function passwordUpdated(): void
{
Notification::make()
->title('Password Updated')
->body('Your password has been updated.')
->success();
->send();
}
}
/**
* Configure the roles and permissions that are available within the application.
*/
protected function configurePermissions(): void
{
FilamentCompanies::defaultApiTokenPermissions(['read']);
FilamentCompanies::role('admin', 'Administrator', [
'create',
'read',
'update',
'delete',
])->description('Administrator users can perform any action.');
FilamentCompanies::role('editor', 'Editor', [
'read',
'create',
'update',
])->description('Editor users have the ability to read, create, and update.');
}
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;
use Wallo\FilamentCompanies\Enums\Feature;
use Wallo\FilamentCompanies\Enums\Provider;
class FilamentCompaniesServiceProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
FilamentCompanies::make()
->socialite(
providers: [
Provider::Github,
Provider::Gitlab,
Provider::Google,
Provider::Facebook,
Provider::Linkedin,
Provider::LinkedinOpenId,
Provider::Bitbucket,
Provider::Slack,
Provider::Twitter,
Provider::TwitterOAuth2,
],
features: [
Feature::RememberSession,
Feature::ProviderAvatars,
Feature::GenerateMissingEmails,
Feature::LoginOnRegistration,
Feature::CreateAccountOnFirstLogin,
]
)
)
}
}
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Mailgun, Postmark, AWS and more. This file provides the de facto
| location for this type of information, allowing packages to have
| a conventional file to locate the various service credentials.
|
*/
'github' => [
'client_id' => env('GITHUB_CLIENT_ID'),
'client_secret' => env('GITHUB_CLIENT_SECRET'),
'redirect' => 'https://filament.test/company/oauth/github/callback',
],
// Access a user's currently selected company...
$user->currentCompany : Wallo\FilamentCompanies\Company
// Access all of the companies (including owned companies) that a user belongs to...
$user->allCompanies() : Illuminate\Support\Collection
// Access all of a user's owned companies...
$user->ownedCompanies : Illuminate\Database\Eloquent\Collection
// Access all of the companies that a user belongs to but does not own...
$user->companies : Illuminate\Database\Eloquent\Collection
// Access a user's "personal" company...
$user->personalCompany() : Wallo\FilamentCompanies\Company
// Determine if a user owns a given company...
$user->ownsCompany($company) : bool
// Determine if a user belongs to a given company...
$user->belongsToCompany($company) : bool
// Get the role that the user is assigned on the company...
$user->companyRole($company) : \Wallo\FilamentCompanies\Role
// Determine if the user has the given role on the given company...
$user->hasCompanyRole($company, 'admin') : bool
// Access an array of all permissions a user has for a given company...
$user->companyPermissions($company) : array
// Determine if a user has a given company permission...
$user->hasCompanyPermission($company, 'server:create') : bool