PHP code example of bishopb / laravel-forums

1. Go to this page and download the library: Download bishopb/laravel-forums 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/ */

    

bishopb / laravel-forums example snippets


'providers' => array (
    // ... other providers here
    'BishopB\Forum\ForumServiceProvider',
),

use \BishopB\Forum\User;
use \BishopB\Forum\UserRepository;
use \BishopB\Forum\RoleRepository;

function create_an_app_user() {
    // make this app user a member moderator
    $user = UserRepository::createWithRoles(
        [
            'Name' => 'Jane Q. Doe',
            'Password' => User::crypt_password('the-initial-password', 'vanilla'),
            'HashMethod' => 'vanilla',
        ],
        [ RoleRepository::member(), RoleRepository::moderator() ]
    );
}

// in app/start.php
use \Illuminate\Auth\UserInterface as AppUser;
use \BishopB\Forum\User as VanillaUser;

\App::bind('BishopB\Forum\UserMapperInterface', function () {
    $mapper = new \BishopB\Forum\UserMapperSynchronicity();
    $mapper->create_guest_account = null; // when null, guests will not be able
                                          // to access the forums. Change to a 
                                          // closure to implement
    $mapper->create_account_for = function ($vanillaID, AppUser $user) {
        return UserRepository::createWithRoles(
            [
                'UserID' => $vanillaID,
                'Name' => $user->lastCommaFirstName,
                'Password' => str_random(64),
                'HashMethod' => 'random',
            ],
            [ RoleRepository::member() ]
        );
    };
    $mapper->update_account_for = function (AppUser $user, VanillaUser $vanillaUser) {
        $vanillaUser->Name = $user->lastCommaFirstName;
        $vanillaUser->save();
    };
    return $mapper;
});

\App::bind('BishopB\Forum\UserMapperInterface', function () {
    $mapper = new \BishopB\Forum\UserMapperByClosure();
    $mapper->setClosure(function (\Illuminate\Auth\UserInterface $user = null) {
        // do whatever you want, it should return a \BishopB\Forum\User
    });
    return $mapper;
});

\Event::listen('forum.event', function ($data) {
    // use $data according to the plugin guidelines
});