<commit_before><?php

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\Realms\Server;

class RealmsController extends Controller
{
    public function listing()
    {
        return view('realms', ['realms' => Server::all()]);
    }
}<commit_msg>Add create Realm controller method.<commit_after><?php

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\Realms\Player;
use App\Realms\Server;
use Illuminate\Http\Request;

class RealmsController extends Controller
{
    /**
     * Get Realms management page.
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function listing()
    {
        return view('realms', ['realms' => Server::all()]);
    }

    /**
     * Create new Realm.
     * Should be called with AJAX.
     *
     * @param Request $request
     * @return mixed
     */
    public function create(Request $request)
    {
        // Validate request.
        $this->validate($request, [
            'name' => 'required|max:32',
            'owner' => 'required|max:64'
        ]);
        $realmName = $request->input('name');
        $owner = $request->input('owner');

        // Get owner's UUID
        $player = new Player(null, $owner);
        $player->lookupFromApi();
        if ($player->uuid === null) {
            // Bad username error.
            return [
                'success' => false,
                'error' => 'bad_username'
            ];
        }

        // Create Realm.
        $realm = new Server();
        $realm->name = $realmName;
        $realm->owner = $player;
        $realm->state = Server::STATE_UNINITIALIZED;
        $realm->save();

        // All good!
        return [
            'success' => true
        ];
    }
}
{'fraction_non_alphanumeric': 0.14269850083287064, 'fraction_numerical': 0.002220988339811216, 'mean_word_length': 2.023489932885906, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3435780', 'n_tokens_mistral': 532, 'n_tokens_neox': 537, 'n_words': 114}