Categories
Learning

How to use “where” with “pluck” in laravel?

Hello,

Here is the quick solution:

$categoryId = ProductCategory::where('id',$id)->pluck('categoryId')[0];
$parentId = ProductCategory::where('id',$id)->pluck('parentId')[0];
        
print_r($categoryId);
print_r($parentId);
        

Plucking it array index 0 as the return from pluck is array based so indexing gives us the value for the particular column you need to pluck from table.

Hope this will give you an idea or solution to your problem.

Happy Learning, Happy Learning Laravel!