GithubHelp home page GithubHelp logo

Comments (13)

overtrue avatar overtrue commented on May 30, 2024 2

If you are using id to created data, you must put the second argument like this:

$post:  id: 119

// using id
$user->toggleLike(119, 'App\Post');

// using model
$user->toggleLike($post);

So, plz update the following line:

$user->toggleLike($postid);

to

$user->toggleLike($postid, Post::class);

from laravel-follow.

overtrue avatar overtrue commented on May 30, 2024

Auth::user()->hasLiked(119, 'App\Post')

from laravel-follow.

a-ssassi-n avatar a-ssassi-n commented on May 30, 2024

I tried this, but still it's returning false. Any other solutions please

from laravel-follow.

overtrue avatar overtrue commented on May 30, 2024

Looks like your database is a user liked another user, not liked a post.

from laravel-follow.

a-ssassi-n avatar a-ssassi-n commented on May 30, 2024

Please review this snapshot.

capture

The followable type is App\User in the database table. Where did I do wrong?

from laravel-follow.

overtrue avatar overtrue commented on May 30, 2024

yes, it means user:1 liked user:119

from laravel-follow.

overtrue avatar overtrue commented on May 30, 2024
$user = App\User::find(1);

dd($user->hasLiked(119)); // true

from laravel-follow.

a-ssassi-n avatar a-ssassi-n commented on May 30, 2024

But user:119 doesn't exists in the database. Also, when I do (Auth::user()->hasLiked(119, 'App\User') It also returns false.

from laravel-follow.

overtrue avatar overtrue commented on May 30, 2024

How does you inserted the data? can you show me the code?

from laravel-follow.

a-ssassi-n avatar a-ssassi-n commented on May 30, 2024

User Model:

use Overtrue\LaravelFollow\Traits\CanBeFollowed;
use Overtrue\LaravelFollow\Traits\CanFollow;
use Overtrue\LaravelFollow\Traits\CanLike;
class User extends Authenticatable
{
    use CanFollow, CanBeFollowed, CanLike;

Post Model

use Overtrue\LaravelFollow\Traits\CanBeLiked;
class Post extends Model
{
    use CanBeLiked;

Controller

 public function likePost($postid)
    {
        $user = Auth::user();
        $user->toggleLike($postid);
        return Response::json(array(
                    'success' => true
                )); 
        //return redirect()->back()->with('message', 'Liked');
    }

And the route has a get method to call likePost function

from laravel-follow.

overtrue avatar overtrue commented on May 30, 2024

https://github.com/overtrue/laravel-follow#parameters

from laravel-follow.

a-ssassi-n avatar a-ssassi-n commented on May 30, 2024

Thanks. It worked.

from laravel-follow.

overtrue avatar overtrue commented on May 30, 2024

😄

from laravel-follow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.