vendredi 13 mai 2022

how add image upload in TinyMCeditor laravel

i'm trying to upload images in between my blog content but when i select images from the gallery its shoes the error Route[/] not found, even though the route is defined correctly create.blade.php

<div class="wt-formtheme wt-userform wt-userformvtwo">
{!! Form::textarea('content', null, ['class' => 'wt-tinymceeditor', 'id' => 'wt-tinymceeditor', 'placeholder' => trans('lang.blog_desc_note')]) !!}
 <input name=image type=file id="contentpics" onchange="">
</div>

app.js

tinymce.init({
    selector: "textarea.wt-tinymceeditor",
    height: 300,
    theme: "modern",
    plugins: [
      "code advlist autolink lists link image charmap print preview hr anchor pagebreak",
    ],
    menubar: false,
    statusbar: false,
    toolbar1:
      "undo redo | insert | image | styleselect | bold italic | alignleft aligncenter alignright alignjustify code",
          image_advtab: true,
          automatic_uploads:true,
          images_upload_url:'/upload',
          file_picker_callback: function(callback, value, meta) {
            if (meta.filetype == 'image') {
              console.log("im image")
              $('#contentpics').trigger('click');
              $('#contentpics').on('change', function() {
                var file = this.files[0];
                console.log(file);
                var reader = new FileReader();
                reader.onload = function(e) {
                  callback(e.target.result, {
                    alt: ''
                  });
                };
                reader.readAsDataURL(file);
              });
            }
          },
    image_advtab: true,
    inline_styles: true,
    remove_script_host: false,
    extended_valid_elements: "span[style],i[class]",
    relative_urls: false,
  });

web.php

 Route::post('/upload', 'BlogController@upload');

BlogController.php

public function upload(Request $request){
            $fileName=$request->file('contentpics')->getClientOriginalName();
            $path=$request->file('contentpics')->storeAs('uploads', $fileName, 'public');
            return response()->json(['location'=>"/storage/$path"]); 
    
        }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/TOb9MKS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire