I have a Laravel 4 installation, which I have added both Confide and Entrust packages.
I am trying to build an admin interface to manage users, roles, and permissions.
I have created a resourceful controller for permissions and both the add and destroy functions work fine, but the edit does not. The record is not updating the values in the database.
Here is the code for my controller:
<?php
class PermissionController extends BaseController {
protected $permission;
public function __construct(Permission $permission)
{
$this->permission = $permission;
}
...
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$permission = $this->permission->find($id);
if (is_null($permission))
{
return Redirect::route('permissions.index');
}
return View::make('permissions.edit', compact('permission'));
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$input = array_except(Input::all(), '_method');
$validation = Validator::make($input, Permission::$rules);
if ($validation->passes())
{
$permission = $this->permission->find($id);
// create name from display_name
$input['name'] = $this->_machine_str($input['display_name']);
try {
$permission->update($input);
$queries = DB::getQueryLog();
$last_query = end($queries);
print_r($queries);
die();
} catch (Exception $e) {
var_dump($e->getTraceAsString());
die();
}
return Redirect::route('permissions.show', $id);
}
return Redirect::route('permissions.edit', $id)
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors.');
}
...
}
And the model:
<?php
use Zizaco\Entrust\EntrustPermission;
class Permission extends EntrustPermission
{
/**
*Soft delete enabled.
*
* @var boolean
*/
protected $softDelete = true;
protected $guarded = array('id');
/**
* Ardent validation rules
*
* @var array
*/
public static $rules = array(
'display_name' => 'required|between:4,32'
);
}
The update works if I chnage the model to extend Eloquent, so I might be something to do with the EntrustPermission model.
I have also checked the database calls, which only show the selecting not any kind of update.