Nicho's avatar
Level 1

How to add a video in the gallery in laravel

I want to add a video in to the row of gallery column, i am able to upload an image into the row of gallery, and i want to upload the video into that row of gallery as well

The Blade :

<div class="form-group">
                <label class="control-label">{{__("Gallery")}}</label>
                {!! \Modules\Media\Helpers\FileHelper::fieldGalleryUpload('gallery',$row->gallery) !!}
            </div>

The FileHelper :

public static function fieldGalleryUpload($inputId = '', $oldValue = '')
    {
        $oldIds = $oldValue ? explode(',', $oldValue) : [];
        ob_start();
        ?>
        <div class="dungdt-upload-multiple <?php if (!empty($file)) echo 'active' ?>" data-val="<?php echo $oldValue ?>">
            <div class="attach-demo d-flex">
                <?php
                foreach ($oldIds as $id) {
                    $file = (new MediaFile())->findById($id);
                    if (!empty($file)) {
                        ?>
                        <div class="image-item">
                            <div class="inner">
                                <?php
                                $oldPath = '';
                                if (!empty($file)){$oldPath = $file->getEditPath();}
                                ?>
                                <a class="edit-img btn btn-sm btn-primary edit-multiple" data-id="<?php echo $id ?>"  data-file="<?php echo $oldPath ?>"><i class="fa fa-edit"></i></a>
                                <span class="delete btn btn-sm btn-danger"><i class="fa fa-trash"></i></span><img src="<?php echo FileHelper::url($file, 'thumb').'?time='.strtotime('now') ?>" class="image-responsive image-preview">
                            </div>
                        </div>
                        <?php
                    }
                }
                ?>
            </div>
            <div class="upload-box" v-show="!value">
                <input type="hidden" name="<?php echo $inputId ?>" v-model="value" value="<?php echo htmlspecialchars($oldValue) ?>">
                <div class="text-left">
                    <span class="btn btn-info btn-sm btn-field-upload" @click="openUploader"><i class="fa fa-plus-circle"></i> <?php echo __("Select images") ?></span>
                </div>
            </div>
        </div>
        <?php
        return ob_get_clean();
    }
0 likes
5 replies
Nicho's avatar
Level 1

@tisuchi So that code is for uploading and put photos in to the gallery and save it into an array, and now i want to do the same but with video. And yeah forgive me, i know it's not how i should and would write a laravel code, but it's from the previous freelance dev, so i stuck with this, forgive me

tisuchi's avatar
tisuchi
Best Answer
Level 70

@Nicho So my opinion is you should re-write the part you touch. Because there is no point to maintain such legacy code that pulls you back from your development process.

The general process for how to upload videos:

  • Upload a video file somewhere in your app (normally in the /storage directory)
  • Get the relative path of the uploaded file (e.g. where/did/you/upload/your/videofile)
  • Create a new entry in DB against the new video file and in one column keep the relative path where you stored the file.

Please or to participate in this conversation.