PHP code example of tapp / filament-lms

1. Go to this page and download the library: Download tapp/filament-lms 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/ */

    

tapp / filament-lms example snippets


'tenancy' => [
    'enabled' => true,
    'model' => \App\Models\Team::class,
    'relationship_name' => 'team', // optional
    'column' => 'team_id', // optional
],

use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasTenants;
use Filament\Panel;
use Illuminate\Support\Collection;

class User extends Authenticatable implements FilamentUser, HasTenants
{
    // Allow users to access the LMS panel
    public function canAccessPanel(Panel $panel): bool
    {
        return true; // Or add custom logic
    }

    // Define the teams relationship
    public function teams(): BelongsToMany
    {
        return $this->belongsToMany(Team::class);
    }

    // Return all teams the user can access
    public function getTenants(Panel $panel): Collection
    {
        return $this->teams;
    }

    // Check if user can access a specific team
    public function canAccessTenant(Model $tenant): bool
    {
        return $this->teams()->whereKey($tenant)->exists();
    }
}

use Filament\Models\Contracts\HasName;

class Team extends Model implements HasName
{
    public function getFilamentName(): string
    {
        return $this->name;
    }
}



use Filament\Navigation\NavigationItem;

return [
    'theme' => 'default',
    'font' => 'Poppins',
    'home_url' => '/lms',
    'brand_name' => 'LMS',
    'brand_logo' => '',
    'brand_logo_height' => null,
    
    // Certificate customization
    'certificate_logo' => '', // Falls back to brand_logo if not set
    'certificate_show_signatures' => true, // Show signature lines on certificates
    'certificate_show_id' => true, // Show unique certificate ID
    
    'vite_theme' => '',
    'colors' => [],
    'awards' => [
        'Default' => 'default',
    ],
    'top_navigation' => false,
    'show_exit_lms_link' => true,
];


'certificate_logo' => 'images/certificate-logo.png',

'certificate_show_signatures' => true, // Show signature lines
'certificate_show_signatures' => false, // Hide signature lines

'certificate_show_id' => true, // Show unique certificate ID
'certificate_show_id' => false, // Hide certificate ID

return [
    // General branding
    'brand_name' => 'Acme Learning Academy',
    'brand_logo' => 'images/brand-logo.png',
    
    // Certificate-specific settings
    'certificate_logo' => 'images/certificate-seal.png', // Use a different logo for certificates
    'certificate_show_signatures' => true, // Include signature lines
    'certificate_show_id' => true, // Include unique certificate ID
    
    // Other settings...
];

use Tapp\FilamentLms\LmsNavigation;
use Filament\Navigation\NavigationItem;

public function boot(): void
{
    LmsNavigation::addNavigation('lms',
        NavigationItem::make('Home')
            ->icon('heroicon-o-home')
            ->url(fn (): string => '/'),
    );
}

use Illuminate\Support\Facades\Gate;

class AuthServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Gate::define('viewLmsReporting', function ($user) {
            // Customize this based on your application's needs
            return $user->hasRole('admin') || $user->hasPermission('view-lms-reporting');
        });
    }
}

'restrict_course_visibility' => true,

use Tapp\FilamentLms\RelationManagers\CoursesRelationManager;
use Tapp\FilamentLms\Actions\AssignCoursesBulkAction;

// In your UserResource.php
public static function getRelations(): array
{
    return [
        CoursesRelationManager::class,
        // ... other relation managers ...
    ];
}

// In your UserResource.php
public static function table(Table $table): Table
{
    return $table
        // ...
        ->bulkActions([
            AssignCoursesBulkAction::make(),
            // ... other bulk actions ...
        ]);
}

use Tapp\FilamentLms\Traits\FilamentLmsUser;

class User extends Authenticatable
{
    use FilamentLmsUser {
        FilamentLmsUser::isCourseVisibleForUser as filamentLmsIsCourseVisibleForUser;
    }

    // ...

    public function isCourseVisibleForUser($course): bool
    {
        if ($this->hasAnyRole('admin', 'super_admin')) {
            return true;
        }
        // Call the trait's original method
        return $this->filamentLmsIsCourseVisibleForUser($course);
    }
}

use Tapp\FilamentLms\Traits\FilamentLmsUser;

class User extends Authenticatable
{
    use FilamentLmsUser;

    // ...

    public function canAccessStep(Step $step): bool
    {
        // Allow admins to access all steps
        if ($this->hasRole('admin')) {
            return true;
        }

        // Fall back to default behavior (sequential step completion)
        return parent::canAccessStep($step);
    }
}

use Tapp\FilamentLms\Traits\FilamentLmsUser;

class User extends Authenticatable
{
    use FilamentLmsUser;

    // ...

    public function canEditStep(Step $step): bool
    {
        // Allow admins to edit all steps
        if ($this->hasRole('admin') || $this->hasRole('super_admin')) {
            return true;
        }

        // Allow course creators to edit their own courses
        if ($this->hasRole('instructor') && $step->lesson->course->created_by === $this->id) {
            return true;
        }

        // No edit permissions for other users
        return false;
    }
}
 sh
php artisan vendor:publish --provider="Tapp\FilamentLms\FilamentLmsServiceProvider"
 php
class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                \Tapp\FilamentLms\Lms::make(),
            ])
    }
}
js
module.exports = {
  content: [
    // ... your existing content paths
    './vendor/tapp/filament-lms/resources/views/**/*.blade.php',
    './vendor/tapp/filament-form-builder/resources/views/**/*.blade.php',
  ],
  // ... rest of your config
}
bash
php artisan migrate