File: D:/HostingSpaces/SBogers84/zuiderbos.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";
/**
* 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();
// Check if schools isset else make it an empty array
if(!isset($data['schools'])) $data['schools'] = [];
// 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*/
}
}