mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-11 15:31:06 +03:30
fix upload
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Media;
|
||||
@@ -13,7 +14,9 @@ class UploadController extends Controller
|
||||
{
|
||||
$FileType = 'image';
|
||||
$rules = [
|
||||
"file" => "required|mimes:pdf,jpeg,png,jpg,doc,docx|max:2048"
|
||||
"file" => "required|mimes:pdf,jpeg,png,jpg,doc,docx|max:2048",
|
||||
"batch_id" => "required",
|
||||
"model_type" => "required|string",
|
||||
];
|
||||
$this->validate($request, $rules);
|
||||
|
||||
@@ -21,8 +24,9 @@ class UploadController extends Controller
|
||||
$FileType = 'document';
|
||||
}
|
||||
|
||||
$modelType = Str::ucfirst($request->model_type);
|
||||
if ($request->model_id !== null && is_numeric($request->model_id)) {
|
||||
$Model = 'App\\'.$request->model_type;
|
||||
$Model = 'App\\'.$modelType;
|
||||
$Object = $Model::findOrFail($request->model_id);
|
||||
if ($Object) {
|
||||
if($FileType == 'image'){
|
||||
@@ -49,7 +53,7 @@ class UploadController extends Controller
|
||||
$MediaData = [
|
||||
'model_id' => $Object->id,
|
||||
'batch_id' => $request->batch_id,
|
||||
'model_type' => 'App\\'.$request->model_type,
|
||||
'model_type' => 'App\\'.$modelType,
|
||||
'path' => $Path,
|
||||
'user_id' => auth('api')->user()->id,
|
||||
'file_name' => $FileName,
|
||||
@@ -83,7 +87,7 @@ class UploadController extends Controller
|
||||
$MediaData = [
|
||||
'model_id' => null,
|
||||
'batch_id' => $request->batch_id,
|
||||
'model_type' => 'App\\'.$request->model_type,
|
||||
'model_type' => 'App\\'.$modelType,
|
||||
'path' => $Path,
|
||||
'user_id' => auth('api')->user()->id,
|
||||
'file_name' => $FileName,
|
||||
|
||||
Reference in New Issue
Block a user