GithubHelp home page GithubHelp logo

Comments (4)

overtrue avatar overtrue commented on June 9, 2024 1

@a-ssassi-n You can use pivot feature of laravel: https://laravel.com/docs/5.7/eloquent-relationships#updating-many-to-many-relationships

// follow
$user->follow($other, ['is_approved' => false]); // maybe default as false

//approve
$user->followers()->updateExistingPivot($other->id, ['is_approved' => true]);

// access pivot attributes
foreach ($user->followers as $follower) {
       $follower->pivot->is_approved; 
}

from laravel-follow.

overtrue avatar overtrue commented on June 9, 2024 1

I will refactor this project.

from laravel-follow.

lukecurtis93 avatar lukecurtis93 commented on June 9, 2024

Hi I feel like i need to update this issue for a specific issue I'm having.

I need to grab the is_approved parameter for example. Updating is fine but on my backend I'm unable to query this relationship I feel like the following is the reason:
https://github.com/overtrue/laravel-follow/blob/master/src/Traits/CanFollow.php#L108

For example doing the following will return null:

//Find if user 1 is following user 2 and if they are approved
>>> User::find(1)->followings(User::class)->wherePivot('followable_id',2)->first()->pivot->is_approved
>>> null

Is there a way we can override or add in additional withPivot attributes?

from laravel-follow.

mreduar avatar mreduar commented on June 9, 2024

So adding that column right now is not convenient until you fix the bug? @overtrue

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.