Mpociot\Reanimate\ReanimateModels::restoreModel PHP Method

restoreModel() public method

Undo delete a model with a given primary key
public restoreModel ( $primary_key, $obj, $customIndexRoute = "" ) : Illuminate\Http\RedirectResponse
$primary_key int
$obj
return Illuminate\Http\RedirectResponse
    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");
        }
    }