src/Foundation/Uploads/Uploader.php
/**
     * Generates a JSON response for bootstrap-fileinput jQuery plugin.
     *
     * @param Request $request
     * @param         $uploadedFilePath
     *
     * @return array
     */
Generates a JSON response for bootstrap-fileinput jQuery plugin.
@param Request $request
@param         $uploadedFilePath

@return array
Generates a JSON response for bootstrap - fileinput jQuery plugin . @param Request $request @param $uploadedFilePath @return array
protected function generateFancyUploadResponse(Request $request, $uploadedFilePath)
    {
        $mimeType = static::detectByFilename($uploadedFilePath);
        $isMulti = $request->input('multi') && $request->input('multi') == 'true';
        $return = [
            'append'               => $isMulti ? true : false,
            'initialPreview'       => [$uploadedFilePath], 
            'initialPreviewAsData' => true,
            'initialPreviewCount'  => 1,
            'initialPreviewConfig' => [
                [
                    'filetype' => $mimeType,
                    'type'     => static::guessFileTypeByMimeType($mimeType),
                    'width'    => '120px',
                ],
            ],
        ];
        $table = $request->input('related_table');
        $field = $request->input('related_field');
        $id = $request->input('related_id');
        if ($isMulti) {
            $media = Media::create([
                'related_id'    => $id,
                'related_table' => $table,
                'related_field' => $field,
                'position'      => $request->input('file_id'),
                'media'         => $uploadedFilePath,
                'media_type'    => 'image',
            ]);
            $return['initialPreviewConfig'][0]['key'] = $media->id;
            $return['initialPreviewConfig'][0]['extra'] = [
                'key'           => $media->id,
                'related_table' => $table,
                'related_field' => $field,
                'related_id'    => $id,
            ];
        } else {
            DB::table($table)->where('id', $id)->update([
                $field => $uploadedFilePath,
            ]);
            $return['initialPreviewConfig'][0]['key'] = null;
            $return['initialPreviewConfig'][0]['extra'] = [
                'related_table' => $table,
                'related_field' => $field,
                'related_id'    => $id,
            ];
        }
        return $return;
    }
protected function generateFancyUploadResponse ( Request $ request , $ uploadedFilePath ) { $ mimeType = static :: detectByFilename ( $ uploadedFilePath ) ; $ isMulti = $ request -> input ( 'multi' ) && $ request -> input ( 'multi' ) == 'true' ; $ return = [ 'append' => $ isMulti ? true : false , 'initialPreview' => [ $ uploadedFilePath ] , 'initialPreviewAsData' => true , 'initialPreviewCount' => 1 , 'initialPreviewConfig' => [ [ 'filetype' => $ mimeType , 'type' => static :: guessFileTypeByMimeType ( $ mimeType ) , 'width' => '120px' , ] , ] , ] ; $ table = $ request -> input ( 'related_table' ) ; $ field = $ request -> input ( 'related_field' ) ; $ id = $ request -> input ( 'related_id' ) ; if ( $ isMulti ) { $ media = Media :: create ( [ 'related_id' => $ id , 'related_table' => $ table , 'related_field' => $ field , 'position' => $ request -> input ( 'file_id' ) , 'media' => $ uploadedFilePath , 'media_type' => 'image' , ] ) ; $ return [ 'initialPreviewConfig' ] [ 0 ] [ 'key' ] = $ media -> id ; $ return [ 'initialPreviewConfig' ] [ 0 ] [ 'extra' ] = [ 'key' => $ media -> id , 'related_table' => $ table , 'related_field' => $ field , 'related_id' => $ id , ] ; } else { DB :: table ( $ table ) -> where ( 'id' , $ id ) -> update ( [ $ field => $ uploadedFilePath , ] ) ; $ return [ 'initialPreviewConfig' ] [ 0 ] [ 'key' ] = null ; $ return [ 'initialPreviewConfig' ] [ 0 ] [ 'extra' ] = [ 'related_table' => $ table , 'related_field' => $ field , 'related_id' => $ id , ] ; } return $ return ; }
Generates a JSON response for bootstrap-fileinput jQuery plugin.
Generates a JSON response for bootstrap - fileinput jQuery plugin .
// todo: not always an image