public function restoreModel($primary_key, $obj, $customIndexRoute = "")
{
$model = $obj->withTrashed()->where($obj->getKeyName(), "=", (int) $primary_key)->first();
$modelClass = new \ReflectionClass(get_class($obj));
$modelName = lcfirst($modelClass->getShortName());
// Try to auto-generate the indexRoute if it doesn't exist
if ($customIndexRoute != "") {
$indexRoute = $customIndexRoute;
} elseif (isset($this->indexRoute)) {
$indexRoute = $this->indexRoute;
} else {
// Autogenerate index route
$indexRoute = $modelName . "Index";
}
if (!is_null($model)) {
$model->restore();
return Redirect::route($indexRoute)->with("message", $modelName . ".undo.restored");
} else {
return Redirect::route($indexRoute)->with("message", $modelName . ".undo.invalid");
}
}