PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] Laravel Relational Table if record exist

 March 08, 2022     laravel, mysql     No comments   

Issue

I want to select only the products that have a record in the relational table in the selectbox.

For example I just want to get product name which is product_id in the monthly_records table

Tables;

Products(ID, product_name)

Suppliers(ID, supplier_name)

monthly_records(ID,pruduct_id,supplier_id,date)

Solution

Eloquent has() method is what you are looking for. With that you can do something like:

Product::has('monthlyRecords')->pluck('name');


Answered By - P. K. Tharindu
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing