0

I'm using Mysql on my php laravel project.

I have two columns:

column a:       column b:
0               a
1               b
1               c
0               d

I connected them with foreign key, but how can I do it with 'where' query?

I mean that e.g column b must receive column a values where value = 0?

  • Please show your current attempt and describe what is the issue with it. And add a clarification about your term *foreign key* because in SQL it has special meaning that is not what you are talking about – astentx Oct 23 '21 at 07:36
  • And when the value of `column_a` is not 0 what happens then? This looks like a roundabout way to implement [polymorphism](https://laravel.com/docs/8.x/eloquent-relationships#polymorphic-relationships) – apokryfos Oct 23 '21 at 07:41

1 Answers1

0

You Can Do Something Like This

$blog = Blog::with(['posts' => function ($q) {
   $q->where('column','value'); // query posts table
}, 'posts.comments' => function ($q) {
   $q->where('commentsColumn','anotherValue'); // query comments table
}])->find(1);
Amiyo Ghosh
  • 47
  • 1
  • 8