public static function sendItemNotFoundResponse(CmfDbModel $model)
 {
     return response()->json(['_message' => CmfConfig::transBase('.error.resource_item_not_found'), 'redirect' => 'back', 'redirect_fallback' => route('cmf_items_table', ['table_name' => $model->getTableName()])], 404);
 }
Пример #2
0
 /**
  * @param CmfDbModel $model
  * @param string $relationAlias
  * @param array $scannedModels
  * @param int $depth
  * @return bool|\PeskyCMF\Db\CmfDbModel
  * @throws \PeskyORM\Exception\DbUtilsException
  * @throws \PeskyORM\Exception\DbTableConfigException
  * @throws ScaffoldException
  * @throws \PeskyORM\Exception\DbModelException
  */
 protected function findRelatedModel(CmfDbModel $model, $relationAlias, array &$scannedModels = [], $depth = 0)
 {
     if ($model->hasTableRelation($relationAlias)) {
         return $model->getRelatedModel($relationAlias);
     }
     $scannedModels[] = $model->getTableName();
     foreach ($model->getTableRealtaions() as $alias => $relationConfig) {
         /** @var CmfDbModel $relModel */
         $relModel = $model->getRelatedModel($alias);
         if (!empty($scannedModels[$relModel->getTableName()])) {
             continue;
         }
         $modelFound = $this->findRelatedModel($relModel, $relationAlias, $scannedModels, $depth + 1);
         if ($modelFound) {
             return $modelFound;
         }
         $scannedModels[] = $relModel->getTableName();
     }
     if (!$depth === 0 && empty($modelFound)) {
         throw new ScaffoldException("Cannot find relation [{$relationAlias}] in model [{$model->getAlias()}] or among its relations");
     }
     return false;
 }