Support the ongoing development of Laravel.io →
Database Eloquent Blade

How can I replace existing relation? At this moment, I have tables:

requirements
Your alt text here

user_requirement
Your alt text here

And I have this relation in User model:

public function requirements(){
    return $this->belongsToMany('\App\Requirement', 'user_requirement')->withTimestamps();
}  

Now I created new table - activities:
Your alt text here

And now, how can I set ID from activities for requirement_id in this relation in model? I do somethink like this:

return $this->belongsToMany('\App\Activities', 'user_requirement', 'requirement_id', 'ID' )->withTimestamps();

But when I'm try to do in view ($req->ID is Activity ID):

@if( !$user->activities()->get()->contains( $req->ID ) ) {
  No activity
@else
  Yes activity
@endif

I'm getting always FALSE

Last updated 3 years ago.
0

Can anyone help?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

vertisan vertisan Joined 26 Aug 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.