mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-13 02:21:08 +03:30
fix migrations
This commit is contained in:
@@ -3,56 +3,84 @@
|
|||||||
namespace App\Services\Media;
|
namespace App\Services\Media;
|
||||||
|
|
||||||
use App\FakeModel;
|
use App\FakeModel;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class MediaHelper
|
class MediaHelper
|
||||||
{
|
{
|
||||||
public static function moveMediaTo($model)
|
public static function moveMediaTo($model) {
|
||||||
{
|
|
||||||
request()->validate([
|
request()->validate([
|
||||||
'batch_id' => 'nullable|string',
|
'file_batch_id' => 'nullable|string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($fakeModel = FakeModel::where('batch_id', request('batch_id'))->first()) {
|
if ($fakeModel = FakeModel::where('batch_id', request('file_batch_id'))->first()) {
|
||||||
foreach ($fakeModel->getMedia('temp_medias') as $media) {
|
foreach($fakeModel->getMedia('temp_files') as $media) {
|
||||||
$media->move($model , 'main_images');
|
if(substr($media->mime_type, 0, 5) == 'image') {
|
||||||
|
$media->move($model, 'images');
|
||||||
|
} else {
|
||||||
|
$media->move($model, 'files');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$fakeModel->delete();
|
$fakeModel->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static function moveTinyMCEMediaTo($model)
|
public static function storeMediaFor(Model $model, string $batchId = null)
|
||||||
// {
|
{
|
||||||
//
|
if (is_null($batchId)) {
|
||||||
// request()->validate([
|
$batchId = request()->input('file_batch_id');
|
||||||
// 'tinymce_batch_id' => 'nullable|string',
|
}
|
||||||
// ]);
|
|
||||||
//
|
$modelName = self::getNamespaceMap($model);
|
||||||
// if ($fakeModel = FakeModel::where('batch_id', request('tinymce_batch_id'))->first()) {
|
|
||||||
// foreach ($fakeModel->getMedia('temp_files') as $media) {
|
if ($fakeModel = FakeModel::where('batch_id', $batchId)->where('model_name', $modelName)->first()) {
|
||||||
// if (substr($media->mime_type, 0, 5) == 'image') {
|
|
||||||
// $media->assign($model, 'tinymce_images');
|
foreach($fakeModel->media()->get() as $media) {
|
||||||
// } else {
|
$media->move($model, $media->collection_name);
|
||||||
// $media->assign($model, 'tinymce_files');
|
}
|
||||||
// }
|
|
||||||
// }
|
$fakeModel->delete();
|
||||||
// $fakeModel->delete();
|
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static function loadMedia($model, ...$collections)
|
private static function getNamespaceMap(Model $model)
|
||||||
// {
|
{
|
||||||
// $model->loadMissing(['media' => function ($query) use ($collections) {
|
return $model->getMorphClass();
|
||||||
// $query->select('id', 'model_type', 'model_id', 'collection_name', 'file_name', 'mime_type', 'size', 'disk', 'order_column');
|
}
|
||||||
// if (!empty($collections)) {
|
|
||||||
// $query->whereIn('collection_name', $collections);
|
public static function moveTinyMCEMediaTo($model) {
|
||||||
// }
|
|
||||||
// }]);
|
request()->validate([
|
||||||
// if ($model->media) {
|
'tinymce_batch_id' => 'nullable|string',
|
||||||
// foreach ($model->media as $media) {
|
]);
|
||||||
// $media->address = $media->getUrl();
|
|
||||||
// }
|
if ($fakeModel = FakeModel::where('batch_id', request('tinymce_batch_id'))->first()) {
|
||||||
// }
|
foreach($fakeModel->getMedia('temp_files') as $media) {
|
||||||
// }
|
if(substr($media->mime_type, 0, 5) == 'image') {
|
||||||
|
$media->assign($model, 'tinymce_images');
|
||||||
|
} else {
|
||||||
|
$media->assign($model, 'tinymce_files');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$fakeModel->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function loadMedia($model, ...$collections) {
|
||||||
|
$model->loadMissing(['media' => function($query) use ($collections) {
|
||||||
|
$query->select('*');
|
||||||
|
if (! empty($collections)) {
|
||||||
|
$query->whereIn('collection_name', $collections);
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
if ($model->media) {
|
||||||
|
foreach ($model->media as $media) {
|
||||||
|
$media->address = $media->getUrl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user