thedevdojo / chatter

Chatter is a Simple Laravel Forum Package
https://devdojo.com/forums
MIT License
897 stars 295 forks source link

Call to undefined method Illuminate\Events\Dispatcher::fire() #247

Open Djusa opened 5 years ago

Djusa commented 5 years ago

I tried creating a new discussion and I get this error, I am using laravel 5.8 and it says fire method is deprecated. Do you think there will be many of similar errors so I should move on to another package, or I could fix it myself?

jgusta commented 5 years ago

Same here with 5.8. looks like this method was deprecated in laravel 5.4 and was an alias to Illuminate\Events\Dispatcher::dispatch(). But it was finally removed in 5.8.

EDIT 4/14/2020: Instead of this, try the solution below by @WouterClaes where they extend the facade rather than edit the vendor file, its much cleaner.

If you want a quick fix for this one problem you can manually change Event::fire to Event::dispatch in these two files in your vendor folder: vendor/devdojo/chatter/src/Controllers/ChatterDiscussionController.php vendor/devdojo/chatter/src/Controllers/ChatterPostController.php

BUT remember that these changes won't persist through composer install (if there is ever an update) and won't be committed to your own git repo unless you move it out of the vendor folder and adjust your own composer.json to point to it for this namespace. Who knows what else doesn't work. Looks like this package has been abandoned and is ignoring pull requests. If possible I would find something else, especially if you are just starting your project.

This issue would be fixed if this pull request is accepted: https://github.com/thedevdojo/chatter/pull/241

Edit: grammar, add PR reference

jgusta commented 5 years ago

EDIT 4/14/2020: Instead of this, try the solution below by @WouterClaes where they extend the facade rather than edit the vendor file, its much cleaner.

A quick and dirty guide for anyone who UPGRADED from Laravel 5.7 to 5.8 AFTER installing this package.

So after upgrading to laravel 5.8 I copied the entire devdojo folder under a folder in my app root called "unvendored"

WARNING: Keep in mind I installed this package when I had laravel 5.7 and ran the commands described in the original readme while I had a regular install under 5.7. I don't know if the migrations will work or the vendor:publish command.

I then changed Dispatcher::fire() to Dispatcher::dispatch() as described in this pull request: https://github.com/thedevdojo/chatter/pull/241

I added this to the main composer

    "autoload": {
        "psr-4": {
            "DevDojo\\": "unvendored/devdojo/"
        }

and added the only production required package: composer require "luketowers/purifier=~3.0"

but then deleted the real chatter package via composer remove devdojo/chatter

now since the vendor package doesnt have the laravel auto package discovery, i had to manually add the service provider to config/app.php under the providers key

DevDojo\Chatter\ChatterServiceProvider::class

Now it seems to work except for the color picker. This is due to a race condition where chatter tries to load the spectrum jquery plugin before jquery is loaded. My fix is pretty ungraceful: I had to remove the "defer" attribute from <script src="{{ asset('js/app.js') }}" defer></script> in resources/views/layouts/app.blade.php. (thanks to this comment https://github.com/thedevdojo/chatter/issues/226#issuecomment-438640209)

So far everything seems to work. I hope an official fix comes out for this package because it is the nicest looking drop in forum.

WouterClaes commented 4 years ago

Another option is to extend the facade to make it use dispatch in stead of fire.

<?php
namespace App\Facades;
use Illuminate\Support\Facades\Event as IlluminateEvent;

class Event extends IlluminateEvent
{

    public static function fire($var)
    {
        parent::dispatch($var);
    }
}

then in config/app.php you can do

// "Event" => Illuminate\Support\Facades\Event::class,
 "Event" => App\Facades\Event::class,

worked for me, but after spending 4 hours trying to make it work and adjust it to my needs I realised I needed some extra options and I could better write a forum myself. What a waste of my time. At least I learned how to extend facades. ;-)

ivopauly commented 4 years ago

@WouterClaes Thnx for your solution, even today this solution is cleaner as what I saw before.

jgusta commented 4 years ago

the @WouterClaes solution is the best solution so far I think. Thanks!

hajar-elazzouzi commented 3 years ago

@WouterClaes Please where I can add the code bellow:

<?php
namespace App\Facades;
use Illuminate\Support\Facades\Event as IlluminateEvent;

class Event extends IlluminateEvent
{

public static function fire($var)
{
    parent::dispatch($var);
}
}
sheharyarKhann commented 3 years ago

@WouterClaes Please where I can add the code bellow:

<?php
namespace App\Facades;
use Illuminate\Support\Facades\Event as IlluminateEvent;

class Event extends IlluminateEvent
{

public static function fire($var)
{
    parent::dispatch($var);
}
}

hey @Hajar-EA do you know where to paste this code?

sheharyarKhann commented 3 years ago

the @WouterClaes solution is the best solution so far I think. Thanks!

can you pls help me?? where should i paste this code in my project??

WouterClaes commented 3 years ago

You have to create a New file in App\Facades , Event.php for example and this file extends illimunateEvent so you can change it in the config file safely so it uses that class.

sheharyarKhann commented 3 years ago

oh okay thank you i solved this issue now i am facing another with the discussion category, do u know where can i put categories?? as when i try to select any its empty there are no categories to select.. [image: image.png]

On Sat, 10 Apr 2021 at 21:31, Wouter Claes @.***> wrote:

You have to create a New file in App\Facades , Event.php for example and this file extends illimunateEvent so you can change it in the config file safely so it uses that class.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/thedevdojo/chatter/issues/247#issuecomment-817162872, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATEKKRVR6DUCWX3T2WJFTKDTIB4MTANCNFSM4HLJ2XMQ .

WouterClaes commented 3 years ago

That's another issue. It seemed to work for me back then, but I did not went through with it so I really dont know. :-)

Good luck! Hopefuly you found the issue already. 😎