Skip to content

Dropzone implementation docs? #303

@royduin

Description

@royduin

Maybe add some information about how to implement Dropzone in the Bootstrap Markdown editor?

How I've implemented it in my Laravel 5.4 project;

package.json:

"bootstrap-markdown": "toopay/bootstrap-markdown",
"dropzone": "^5.1.1",
"markdown": "^0.5.0",

I'm using toopay/bootstrap-markdown there so NPM will get it from Github instead of fetching the latest version which doesn't include Dropzone support, see: #301

bootstrap.js

window.dropzone = require('dropzone');
window.markdown = require('markdown').markdown;
require('bootstrap-markdown/js/bootstrap-markdown.js');

app.scss

@import "node_modules/dropzone/dist/basic";

markdown.js

window.dropzone.autoDiscover = false;
(function(){
    $('textarea.markdown').markdown({
        dropZoneOptions: {
            url: '/media/upload,
            headers: {
                'X-CSRF-Token': document.head.querySelector('meta[name="csrf-token"]').content
            }
        }
    });
})();

MediaController.php

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    $validator = Validator::make($request->all(), ['file' => 'required|image']);

    if ($validator->fails()) {
        return response($validator->errors()->first(), 422);
    }

    return response(env('APP_URL').'/uploads/'.$request->file->store(date('Y'), 'uploads'));
}

To use it, create a textarea with the markdown class in one of your Blade/HTML templates.

This is working nicely, but this fix is needed else the styling isn't correct: #302

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions