<commit_before><?php

namespace Soda\Cms\Http\Controllers;

use Exception;
use Illuminate\Http\Request;
use Soda\Cms\Database\Pages\Interfaces\PageRepositoryInterface;

class PageController extends BaseController
{
    protected $pages;

    public function __construct(PageRepositoryInterface $pages)
    {
        $this->pages = $pages;

        $this->middleware('soda.permission:view-pages');
        $this->middleware('soda.permission:create-pages')->only(['create', 'store']);
        $this->middleware('soda.permission:edit-pages')->only(['edit', 'update']);
        $this->middleware('soda.permission:delete-pages')->only(['delete']);
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $pages = $this->pages->getTree();
        $page_types = $this->pages->getTypes(true);
        $page_types->load('subpage_types');

        return soda_cms_view('data.pages.index', compact('pages', 'page_types'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        try {
            $parentId = $request->input('parentId');
            $pageTypeId = $request->input('pageTypeId');
            $page = $this->pages->createStub($parentId, $pageTypeId);
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'page']));
        }

        return view($page->edit_action, compact('page'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     *
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        try {
            $page = $this->pages->save($request);
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'page']));
        }

        return redirect()->route('soda.pages.edit', $page->getKey())->with('success', trans('soda::messages.created', ['object' => 'page']));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $page = $this->pages->findById($id);

        if (!$page) {
            return $this->handleError(trans('soda::errors.not-found', ['object' => 'page']));
        }

        $page->load('blocks.type.fields', 'type.blocks.type.fields', 'type.fields');
        $blockTypes = $this->pages->getAvailableBlockTypes($page);

        return view($page->edit_action, compact('page', 'blockTypes'));
    }
<commit_msg>Update Page BlockType relationship<commit_after><?php

namespace Soda\Cms\Http\Controllers;

use Exception;
use Illuminate\Http\Request;
use Soda\Cms\Database\Pages\Interfaces\PageRepositoryInterface;

class PageController extends BaseController
{
    protected $pages;

    public function __construct(PageRepositoryInterface $pages)
    {
        $this->pages = $pages;

        $this->middleware('soda.permission:view-pages');
        $this->middleware('soda.permission:create-pages')->only(['create', 'store']);
        $this->middleware('soda.permission:edit-pages')->only(['edit', 'update']);
        $this->middleware('soda.permission:delete-pages')->only(['delete']);
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $pages = $this->pages->getTree();
        $page_types = $this->pages->getTypes(true);
        $page_types->load('subpage_types');

        return soda_cms_view('data.pages.index', compact('pages', 'page_types'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        try {
            $parentId = $request->input('parentId');
            $pageTypeId = $request->input('pageTypeId');
            $page = $this->pages->createStub($parentId, $pageTypeId);
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'page']));
        }

        return view($page->edit_action, compact('page'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     *
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        try {
            $page = $this->pages->save($request);
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'page']));
        }

        return redirect()->route('soda.pages.edit', $page->getKey())->with('success', trans('soda::messages.created', ['object' => 'page']));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $page = $this->pages->findById($id);

        if (!$page) {
            return $this->handleError(trans('soda::errors.not-found', ['object' => 'page']));
        }

        $page->load('block_types.type.fields', 'type.block_types.type.fields', 'type.fields');
        $blockTypes = $this->pages->getAvailableBlockTypes($page);

        return view($page->edit_action, compact('page', 'blockTypes'));
    }

{'fraction_non_alphanumeric': 0.1696539485359361, 'fraction_numerical': 0.0, 'mean_word_length': 2.622107969151671, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, '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': '2543567', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1654, 'n_words': 301}