PHP code example of xoco70 / laravel-tournaments

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

    

xoco70 / laravel-tournaments example snippets


composer 

php artisan vendor:publish --tag=laravel-tournaments --force

php artisan migrate
composer dump-autoload

php artisan db:seed --class=LaravelTournamentSeeder


Route::get('/', 'App\Http\Controllers\TreeController@index')->name('tree.index');
Route::post('/championships/{championship}/trees', 'App\Http\Controllers\TreeController@store')->name('tree.store');
Route::put('/championships/{championship}/trees', 'App\Http\Controllers\TreeController@update')->name('tree.update');

php artisan db:seed --class=LaravelTournamentSeeder


// Create a tournament

$tournament = factory(Tournament::class)->create(['user_id' => Auth::user()->id]);

$championsip = factory(Championship::class)->create(['$tournament_id' => $tournament->id]);

// Optional, if not defined, it will take default in ChampionshipSettings

$settings = factory(ChampionshipSettings::class)->create(['championship_id' => $championship->id]);

// Add competitors to championship

$competitors = factory(\App\Competitor::class,10)->create([
    'championship_id' => $championship->id,
     'user_id' => factory(User::class)->create()->id
]);

// Define strategy to generate

$generation = $championship->chooseGenerationStrategy();

// Generate everything

$generation->run();

// Just generate Tree

$this->generateAllTrees();

// Just generate Fight List

$this->generateAllFights();


$tournament->owner; // get owner
$tournament->venue; // get venue
$tournament->championships; // get championships 

$tournament->isOpen()
$tournament->needsInvitation()

$tournament ->isInternational()
$tournament->isNational() 
$tournament->isRegional()
$tournament->isEstate()
$tournament->isMunicipal()
$tournament->isDistrictal()
$tournament->isLocal()
$tournament->hasNoLevel()

$championship->competitors; // Get competitors
$championship->teams; // Get teams
$championship->fighters; // Get fighters
$championship->category; // Get category
$championship->tournament; // Get tournament
$championship->users; // Get users
$championship->settings; // Get settings
$championship->fightersGroups; // Get groups 
$championship->groupsByRound($numRound = 1); // Get groups for a specific round
$championship->groupsFromRound($numRound = 1); // Get groups from a specific round
$championship->fights; // Get fights
$championship->firstRoundFights; // Get fights for the first round only ( Useful when has preliminary )
$championship->fights($numRound = 1); // Get fights for a specific round

$championship->isPlayoffCompetitor()
$championship->isPlayoffTeam()
$championship->isSingleEliminationCompetitor()
$championship->isSingleEliminationTeam()

$championship->getGroupSize()

$championship->hasPreliminary()
$championship->isPlayOffType()
$championship->isSingleEliminationType()

$group->championship; // Get championship
$group->fights; // Get fights
$group->fighters; // Get fighters
$group->teams; // Get teams
$group->competitors; // Get competitors
$group->users; // Get users

$group->getFighterType() // Should return Team::class or Competitor::class

$competitor->user; // Get user

// Create a team

$team = factory(Team::class)
    ->create([ championship_id' => $championship->id]);

// Add competitor to team 

$team->competitors()->attach($competitor->id);

// Remove competitor from a team 

$team->competitors()->detach($competitor->id);


$fight->group; // Get group
$fight->competitor1; // Get competitor1
$fight->competitor2; // Get competitor2
$fight->team1; // Get team1
$fight->team2; // Get team2

@

@

@

use Illuminate\Support\Facades\Schema;

public function boot()
{
Schema::defaultStringLength(191);
}