HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers33/bbec.nl/workbench/komma/kms/src/Komma/Kms/Posts/PostController.php
<?php

namespace Komma\Kms\Posts;

/**
 * Short description for the file.
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

use Komma\Kms\Core\Kms;
use Komma\Kms\Core\SectionController;
use Komma\Kms\Core\Tree\TreeService;

use Komma\Kms\Posts\Models\Post;

class PostController extends SectionController
{
    protected $slug = "Posts";

    protected $treeService;

    /**
     * Constructor
     * @param Kms         $kms
     * @param PostSection $section
     */
    public function __construct(Kms $kms, PostSection $section)
    {
        parent::__construct($kms, $section);
    }

    public function update()
    {
        // Get id from slug as snake case
        // Directly to snake_case did'nt work
        // First as camel did work
        $camelSlug = camel_case($this->slug);
        $snakeSlug = snake_case($camelSlug);
        $id = \Route::current()->getParameter($snakeSlug);

        // Get all input data
        $data = \Input::all();

        // Load entity in section
        $this->section->loadEntity($id);

        // Push data into attributes
        $this->section->setAttributesData($data);

        // Create a validator
        $validator = $this->section->validateAttributes();

        // Validate
        if($validator->fails())
        {
            return \Redirect::action(get_class($this).'@show', [$this->slug => $id])
                ->withInput()
                ->withErrors($validator->messages());
        }

        // Save the entity
        $this->section->update($id);


        return \Redirect::action(get_class($this).'@show', [$this->slug => $id])
            ->with('success', 'Entity Saved'); // Pass the opened tab*/
    }
}