Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with Laravel 5.8 (Event::fire) #125

Open
jhm-ciberman opened this issue Mar 14, 2019 · 12 comments
Open

Does not work with Laravel 5.8 (Event::fire) #125

jhm-ciberman opened this issue Mar 14, 2019 · 12 comments

Comments

@jhm-ciberman
Copy link

Error: Call to undefined method Illuminate\Events\Dispatcher::fire()
Laravel Version: 5.8

The method ´Event::fire()´ has been deprecated (and removed)
It should be replaced with ´Event::dispatch()´

´´´php

/**
 * @param Model $recipient
 *
 * @return \Hootlex\Friendships\Models\Friendship|false
 */
public function befriend(Model $recipient)
{

    if (!$this->canBefriend($recipient)) {
        return false;
    }

    $friendship = (new Friendship)->fillRecipient($recipient)->fill([
        'status' => Status::PENDING,
    ]);

    $this->friends()->save($friendship);
  
    Event::fire('friendships.sent', [$this, $recipient]); // HERE!!!!!!!!!! 

    return $friendship;

}

´´´

@jhm-ciberman
Copy link
Author

I think this PR solves the issue. Please merge this asap, since my clients app deppends on this package

#124

@hootlex
Copy link
Owner

hootlex commented Mar 14, 2019

@jhm-ciberman the PR is incomplete. When it's fixed and tests pass for all supported Laravel versions I will merge ASAP

@jhm-ciberman
Copy link
Author

For my scenario, I created my own "HasFriends" trait and extended yours overwriting the conflictive methods. So, its not that urgent for me at the moment.
Thanks for the quick answer!

@Solomon04
Copy link

Building on @jhm-ciberman solution I also created a separate trait, here is a what I did:

Create Trait

<?php

namespace App\Traits;


use Hootlex\Friendships\Models\Friendship;
use Hootlex\Friendships\Models\FriendFriendshipGroups;
use Hootlex\Friendships\Status;
use Hootlex\Friendships\Traits\Friendable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Event;

trait FriendableTempFix
{
    use Friendable;

    /**
     * @param Model $recipient
     * @return bool|Friendship
     */
    public function befriend(Model $recipient)
    {
        if (!$this->canBefriend($recipient)) {
            return false;
        }

        $friendship = (new Friendship)->fillRecipient($recipient)->fill([
            'status' => Status::PENDING,
        ]);

        $this->friends()->save($friendship);

        Event::dispatch('friendships.sent', [$this, $recipient]);

        return $friendship;
    }

    /**
     * @param Model $recipient
     * @return mixed
     */
    public function unfriend(Model $recipient)
    {
        $deleted = $this->findFriendship($recipient)->delete();

        Event::dispatch('friendships.cancelled', [$this, $recipient]);

        return $deleted;
    }

    /**
     * @param Model $recipient
     * @return mixed
     */
    public function acceptFriendRequest(Model $recipient)
    {
        $updated = $this->findFriendship($recipient)->whereRecipient($this)->update([
            'status' => Status::ACCEPTED,
        ]);

        Event::dispatch('friendships.accepted', [$this, $recipient]);

        return $updated;
    }

    /**
     * @param Model $recipient
     * @return mixed
     */
    public function denyFriendRequest(Model $recipient)
    {
        $updated = $this->findFriendship($recipient)->whereRecipient($this)->update([
            'status' => Status::DENIED,
        ]);

        Event::dispatch('friendships.denied', [$this, $recipient]);

        return $updated;
    }

    /**
     * @param Model $recipient
     * @return Friendship
     */
    public function blockFriend(Model $recipient)
    {
        // if there is a friendship between the two users and the sender is not blocked
        // by the recipient user then delete the friendship
        if (!$this->isBlockedBy($recipient)) {
            $this->findFriendship($recipient)->delete();
        }

        $friendship = (new Friendship)->fillRecipient($recipient)->fill([
            'status' => Status::BLOCKED,
        ]);

        $this->friends()->save($friendship);

        Event::dispatch('friendships.blocked', [$this, $recipient]);

        return $friendship;
    }

    /**
     * @param Model $recipient
     * @return mixed
     */
    public function unblockFriend(Model $recipient)
    {
        $deleted = $this->findFriendship($recipient)->whereSender($this)->delete();

        Event::dispatch('friendships.unblocked', [$this, $recipient]);

        return $deleted;
    }
}

I am overriding the methods and replaced Event::fire() with Event::dispatch()

Replace Friendable Trait in User Model

Then instead of using the Friendable trait in the user model, use the new trait you just created in place of the Friendable trait.

Note this is just a temporary solution, once the PR fix has been merged, I recommend upgrading your vendor package.

@MarcoCazzaro
Copy link

Hi guys, any news on this issue? Thanks

@Baspa
Copy link

Baspa commented Apr 29, 2019

Still no news?

@jnbn
Copy link

jnbn commented Aug 12, 2019

As no PR's are being accepted you can replace all ::fire methods with ::dispatch in your Friendable trait manually.

@patterueldev
Copy link

As no PR's are being accepted you can replace all ::fire methods with ::dispatch in your Friendable trait manually.

So you have to replace it inside the vendors folder? Not too practical

Btw I'm using Laravel 6 and the issue still exists.

{
    "message": "Call to undefined method Illuminate\\Events\\Dispatcher::fire()",
    "exception": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
    "file": "{rootfolder}/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php",
    "line": 239,
    "trace": [
        {
            "file": "{rootfolder}/vendor/hootlex/laravel-friendships/src/Traits/Friendable.php",
            "line": 35,
            "function": "__callStatic",
            "class": "Illuminate\\Support\\Facades\\Facade",
            "type": "::"
        },

@khacnha
Copy link

khacnha commented Feb 16, 2020

Me too!
"message": "Method Illuminate\\Events\\Dispatcher::fire does not exist.",

@nelson1995
Copy link

Hey Friends has the issue been resolved ?

@Solomon04
Copy link

@jpteruel095 you don't have to edit your vendor file. Just extend the class and override the methods.

@tojo-r27
Copy link

the contributors will must make update with code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants