import not compatible with modules
This commit is contained in:
		| @@ -3,6 +3,7 @@ | ||||
| namespace App\Http\Controllers\Common; | ||||
|  | ||||
| use App\Http\Controllers\Controller; | ||||
| use Module; | ||||
|  | ||||
| class Import extends Controller | ||||
| { | ||||
| @@ -17,6 +18,12 @@ class Import extends Controller | ||||
|     { | ||||
|         $path = $group . '/' . $type; | ||||
|  | ||||
|         return view('common.import.create', compact('group', 'type', 'path')); | ||||
|         if (Module::findByAlias($group) instanceof \Nwidart\Modules\Module) { | ||||
|             $namespace = $group . '::'; | ||||
|         } else { | ||||
|             $namespace = ''; | ||||
|         } | ||||
|  | ||||
|         return view('common.import.create', compact('group', 'type', 'path', 'namespace')); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -8,12 +8,12 @@ use Illuminate\Validation\ValidationException; | ||||
| class Import | ||||
| { | ||||
|  | ||||
|     public static function createFromFile($import, $slug) | ||||
|     public static function createFromFile($import, $slug, $namespace = 'App') | ||||
|     { | ||||
|         $success = true; | ||||
|  | ||||
|         // Loop through all sheets | ||||
|         $import->each(function ($sheet) use (&$success, $slug) { | ||||
|         $import->each(function ($sheet) use (&$success, $slug, $namespace) { | ||||
|             if (!static::isValidSheetName($sheet, $slug)) { | ||||
|                 $message = trans('messages.error.import_sheet'); | ||||
|  | ||||
| @@ -22,7 +22,7 @@ class Import | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             if (!$success = static::createFromSheet($sheet, $slug)) { | ||||
|             if (!$success = static::createFromSheet($sheet, $slug, $namespace)) { | ||||
|                 return false; | ||||
|             } | ||||
|         }); | ||||
| @@ -30,12 +30,12 @@ class Import | ||||
|         return $success; | ||||
|     } | ||||
|  | ||||
|     public static function createFromSheet($sheet, $slug) | ||||
|     public static function createFromSheet($sheet, $slug, $namespace = 'App') | ||||
|     { | ||||
|         $success = true; | ||||
|  | ||||
|         $model = '\App\Models\\' . $slug; | ||||
|         $request = '\App\Http\Requests\\' . $slug; | ||||
|         $model = '\\' . $namespace . '\Models\\' . $slug; | ||||
|         $request = '\\' . $namespace . '\Http\Requests\\' . $slug; | ||||
|  | ||||
|         if (!class_exists($model) || !class_exists($request)) { | ||||
|             return false; | ||||
| @@ -82,11 +82,17 @@ class Import | ||||
|     { | ||||
|         $t = explode('\\', $slug); | ||||
|  | ||||
|         if (empty($t[1])) { | ||||
|             return false; | ||||
|         if (count($t) == 1) { | ||||
|             $title = $slug; | ||||
|         } else { | ||||
|             if (empty($t[1])) { | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             $title = $t[1]; | ||||
|         } | ||||
|  | ||||
|         if ($sheet->getTitle() != str_plural(snake_case($t[1]))) { | ||||
|         if ($sheet->getTitle() != str_plural(snake_case($title))) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| @extends('layouts.admin') | ||||
|  | ||||
| @section('title', trans('import.title', ['type' => trans_choice('general.' . $type, 2)])) | ||||
| @section('title', trans('import.title', ['type' => trans_choice($namespace . 'general.' . snake_case(camel_case($type)), 2)])) | ||||
|  | ||||
| @section('content') | ||||
|     <div class="box box-success"> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user