<commit_before><?php

namespace App\Http\Controllers;

use App\Entities\Grammar;
use App\Http\Forms\Grammars\CreateForm;
use App\Http\Forms\Grammars\EditForm;
use App\Http\Requests\Grammar\GrammarStoreRequest;
use App\Http\Requests\Grammar\GrammarUpdateRequest;
use App\Services\GrammarService;
use Illuminate\Support\Facades\Auth;

class GrammarsController extends Controller
{
    public function __construct()
    {
        $this->middleware('can:delete,grammar', ['only' => ['destroy']]);
        $this->middleware('can:view,grammar', ['only' => ['show']]);
        $this->middleware('can:update,grammar', ['only' => ['edit', 'update']]);
    }

    public function index()
    {
        $grammars = Auth::user()
            ->availableGrammars()
            ->with('owner')
            ->orderBy('created_at', 'desc')
            ->paginate(10);

        return view('grammars.index', compact('grammars'));
    }

    public function show(Grammar $grammar)
    {
        $lastVersion = !$grammar->isLeaf() ? $grammar->leaves()->first() : null;

        return view('grammars.show', compact('grammar', 'lastVersion'));
    }

    public function create()
    {
        $form = $this->form(CreateForm::class, [
            'method' => 'POST',
            'url' => route('grammars.store'),
        ]);

        return view('grammars.create', compact('form'));
    }<commit_msg>perf(laravel): don't select unnecessary fields from db<commit_after><?php

namespace App\Http\Controllers;

use App\Entities\Grammar;
use App\Http\Forms\Grammars\CreateForm;
use App\Http\Forms\Grammars\EditForm;
use App\Http\Requests\Grammar\GrammarStoreRequest;
use App\Http\Requests\Grammar\GrammarUpdateRequest;
use App\Services\GrammarService;
use Illuminate\Support\Facades\Auth;

class GrammarsController extends Controller
{
    public function __construct()
    {
        $this->middleware('can:delete,grammar', ['only' => ['destroy']]);
        $this->middleware('can:view,grammar', ['only' => ['show']]);
        $this->middleware('can:update,grammar', ['only' => ['edit', 'update']]);
    }

    public function index()
    {
        $grammars = Auth::user()
            ->availableGrammars()
            ->with('owner')
            ->orderBy('created_at', 'desc')
            ->paginate(10, ['id', 'name', 'user_id']);

        return view('grammars.index', compact('grammars'));
    }

    public function show(Grammar $grammar)
    {
        $lastVersion = !$grammar->isLeaf() ? $grammar->leaves()->first() : null;

        return view('grammars.show', compact('grammar', 'lastVersion'));
    }

    public function create()
    {
        $form = $this->form(CreateForm::class, [
            'method' => 'POST',
            'url' => route('grammars.store'),
        ]);

        return view('grammars.create', compact('form'));
    }
{'fraction_non_alphanumeric': 0.1737438075017693, 'fraction_numerical': 0.0014154281670205238, 'mean_word_length': 3.097101449275362, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '2223961', 'n_tokens_mistral': 896, 'n_tokens_neox': 893, 'n_words': 151}