Bruno Erceg
Bruno Erceg

Reputation: 83

Trouble installing tinyMCE and UniSharp/laravel-filemanager

So Im trying to install tinyMCE with image upload. I successfully install tinyMCE for simple styling but I cant make the image upload to work. I try to installed UniSharp/laravel-filemanager but when I click on the img icon this is what I get

Sorry page not found

Console

I think somthing is wrong with the cmsURL

This is the index.blade.php

@extends('templates.layout')

@section('head')
  <script src="/wysiwyg/public/js/tinymce/tinymce.min.js"></script>
  <script>
    var editor_config = {
      path_absolute : "{{ URL::to('/') }}/",
      selector : "textarea",
      plugins: [
        "advlist autolink lists link image charmap print preview hr anchor pagebreak",
        "searchreplace wordcount visualblocks visualchars code fullscreen",
        "insertdatetime media nonbreaking save table contextmenu directionality",
        "emoticons template paste textcolor colorpicker textpattern"
      ],
      toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media",
      relative_urls: false,
      file_browser_callback : function(field_name, url, type, win) {
        var x = window.innerWidth || document.documentElement.clientWidth || document.getElementByTagName('body')[0].clientWidht;
        var y = window.innerHeight|| document.documentElement.clientHeight|| document.grtElementByTagName('body')[0].clientHeight;
        var cmsURL = editor_config.path_absolute+'laravel-filemanaget?field_name'+field_name;
        if (type = 'image') {
          cmsURL = cmsURL+'&type=Images';
        } else {
          cmsUrl = cmsURL+'&type=Files';
        }

        tinyMCE.activeEditor.windowManager.open({
          file : cmsURL,
          title : 'Filemanager',
          width : x * 0.8,
          height : y * 0.8,
          resizeble : 'yes',
          close_previous : 'no'
        });
      }
    };

    tinymce.init(editor_config);
  </script>
@stop

@section('body')
  <h1>Hello</h1>
  <form method="post" action="addpost">
    {{ csrf_field() }}
    <textarea name="body"></textarea>
    <button type="submit">Submit</button>
  </form>

@stop

This is the routs

Route::get('/', 'HomeController@index');
Route::post('/addpost', 'HomeController@addPost');
Route::get('/{post}', 'HomeController@post');

And this is the home controller

namespace App\Http\Controllers;

use App\Post;

use Illuminate\Http\Request;

use App\Http\Requests;

class HomeController extends Controller
{
    public function index()
    {
      return view('index');
    }

    public function post(Post $post)
    {
      return view('post', compact('post'));
    }

    public function addPost(Request $request)
    {
      $post = new Post;
      $post->body = $request->body;
      $post->save();

      return back();
    }
}

and I have ony one model Post

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $fillable = ['body'];
}

Upvotes: 0

Views: 664

Answers (1)

TareqMahbub
TareqMahbub

Reputation: 11

If you did the laravel-filemanager installation correctly as suggested here.

Then just putting '/' instead of editor_config.path_absolute when assigning value to cmsURL variable in the code will solve the problem with Laravel 5.4.

Hope it helps. Didn't check this solution for other versions of Laravel.

This solution is only tested for Laravel 5.4.

Upvotes: 1

Related Questions