barryvdh / laravel-elfinder

elFinder bundle for Laravel
739 stars 171 forks source link

Call to a member function hasPermissionTo() on null #197

Open robertnicjoo opened 7 years ago

robertnicjoo commented 7 years ago

Hello,

I used this package on my app in local and it worked just fine but since i moved my app to server i'm getting this error:

Call to a member function hasPermissionTo() on null in AdminMiddleware.php (line 22)

I'm using TinyMCE 4

Here is my AdminMiddleware

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;
use App\User;

class AdminMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
      $user = User::all()->count();
      if (!($user == 1)) {
          if (!Auth::user()->hasPermissionTo('Administer roles & permissions')) //If user does //not have this permission
      {
              abort('401');
          }
      }

      return $next($request);
    }
}

and here is my script on post create page

@section('scripts')
<script type="text/javascript" src="{{asset('js/select2.min.js')}}"></script>
<script>
  var editor_config = {
    path_absolute : "/",
    selector: "textarea.my-editor",
    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 codesample"
    ],
    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media | emoticons charmap | code codesample | forecolor backcolor",
    relative_urls: false,
    remove_script_host: false,
    file_browser_callback : function(field_name, url, type, win) {
      var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
      var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;

      var cmsURL = editor_config.path_absolute + 'laravel-filemanager?field_name=' + field_name;
      if (type == 'image') {
        cmsURL = cmsURL + "&type=Images";
      } else {
        cmsURL = cmsURL + "&type=Files";
      }

      tinymce.activeEditor.windowManager.open({
        file: '<?= route('elfinder.tinymce4') ?>',// use an absolute path!
        title: 'My file manager',
        width: 900,
        height: 450,
        resizable: 'yes'
      }, {
        setUrl: function (url) {
          win.document.getElementById(field_name).value = url;
        }
      });
    }
  };

  tinymce.init(editor_config);
</script>
<script>
  {!! \File::get(base_path('vendor/barryvdh/laravel-elfinder/resources/assets/js/standalonepopup.js')) !!}
</script>
@endsection

Does anyone know why I have this issue and how to fix it?

robertnicjoo commented 7 years ago

anyone?!