public function item($modelName, $itemId = 0)
{
$config = app('itemconfig');
$fieldFactory = app('admin_field_factory');
$actionFactory = app('admin_action_factory');
$columnFactory = app('admin_column_factory');
$actionPermissions = $actionFactory->getActionPermissions();
$fields = $fieldFactory->getEditFields();
//if it's ajax, we just return the item information as json
if ($this->request->ajax()) {
//try to get the object
$model = $config->getModel($itemId, $fields, $columnFactory->getIncludedColumns($fields));
if ($model->exists) {
$model = $config->updateModel($model, $fieldFactory, $actionFactory);
}
$response = $actionPermissions['view'] ? response()->json($model) : response()->json(array('success' => false, 'errors' => 'You do not have permission to view this item'));
//set the Vary : Accept header to avoid the browser caching the json response
return $response->header('Vary', 'Accept');
} else {
$view = view('administrator::index', array('itemId' => $itemId));
//set the layout content and title
$this->layout->content = $view;
return $this->layout;
}
}