dimanche 31 janvier 2016

How to assign certain player-models from a user-pool to one of two teams which belong to a match in Laravel?

Imagine a site where you are a registered user with a given rank to calculate your strenght. You would accidentally click a button, which sets yourself free for the app to get matched with other users. Just as strong as you. After that you can choose from a few options and the match will begin. But this is still a dream.

I have:
- working relations: http://ift.tt/1PJVrAq
- groupable users: $users = User::where('queueing', '1')->where('rank', $request->user()->rank)->get();

I need:
- a clue how to go forward!
- where should and how do I exactly have to tell Laravel to create a new Match (1 Match always has 2 Teams, each with 5 Players from a total of 10 Users)

Appflow:
- User wants to play a match > he will create a player(?), which is part of a team in the match. If the match is over, the user hopefully wants another match > he will create a NEW player, in a NEW team and a NEW match. All from zero again.

I think it's something from http://ift.tt/1mH8Zpu, but I keep only seeing trees...

Part of MatchController if needed:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Auth;
use App\User;
use App\Hero;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class MatchController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function showPlayForm()
    {
        $heroes = Hero::all();

        return view('match.play', ['heroes' => $heroes]);
    }

    public function play(Request $request)
    {
        $this->validate($request, [
            'type' => 'required',
            'role' => 'required',
        ]);

        $this->addToQueue($request);

        return redirect('/queue');
    }

    public function showQueue(Request $request)
    {
        $users = User::where('queueing', '1')->where('rank', $request->user()->rank)->get();

        return view('match.queue', ['users' => $users]);
    }

    public function addToQueue($request)
    {
        $user = $request->user();
        $user->queueing = 1;
        $user->save();
    }
}

Would someone kick me in the right way please?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire