如何在上传中添加当前用户的行ID

How to add row id of current user in upload

我在 laravel PHP 的 dx grid dev extreme 工作,上传 imgae 时遇到问题。 因为图像保存在服务器中,但现在我想通过在单击行时获取用户 ID 来在数据库中添加图像... 我还需要如何更新数据库和前端中的图像..enter image description here

控制器:

public function uploadImg(Request $request)
{
    if($request['fileInput']) {
        $fileName = time().'_'.basename($_FILES["fileInput"]["name"]);
        $targetDir = "storage/users/";
        $targetFilePath = $targetDir . $fileName;

        $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
        $allowTypes = array('jpg','png','jpeg','gif');

        if(in_array($fileType, $allowTypes)) {
            if(move_uploaded_file($_FILES["fileInput"]["tmp_name"], $targetFilePath)) {

                return redirect()->back();
            } else {
                $response['status'] = 'err';
            }
        } else {
            $response['status'] = 'type_err';
        }
        echo json_encode($response);
    }
}

Javascript:

dataField: "avatar",
caption: "Add Image",
width: 200,
alignment: 'center',
formItem: {
    visible: false
},
width: 100,
alignment: 'center',
type:"button",
cellTemplate: function (container, options) {
    $("<div />")
    .text('Upload')
    .on('dxclick', function () {
        // alert('ok');
        $('#fileInput').trigger('click',function() {
            id: "users->id",
            $("#imageform").onValueChanged(function() {
                // uploadUrl: "{{route('upload')}}"
                $("#form").submit();
            })
        });
    })
    .appendTo(container);
    }
},
 {
               dataField: "avatar",
               caption: "Add Image",
               alignment: 'center',
               formItem: {
                   visible: false
               },
               width: 60,
               alignment: 'center',
               cellTemplate: function(container, options) {
                   $('<a/ class="uploadfile" data-userid="' + options.data.id + '">').dxButton({
                           icon: 'upload',
                       })
                       // .text('Upload')
                       .on('dxclick', function() {
                           // alert($(this).data('userid'));
                           $('#userid').val($(this).data('userid'));
                           $('#myModal').modal('show');

                       })
                       .appendTo(container);
               }