'Laravel I need to select Id where supplier name are similar

here is the code

$supplier_id=Supplier::where('supplier', $itest_supplier)->get('supplier_id');

I'm trying to get the id where supplier from the model = to the supplier in $itest_supplier



Solution 1:[1]

If you are looking for a single Supplier:

$supplier_id = Supplier::where('supplier', $itest_supplier)->value('supplier_id');

If you are looking for multiple Suppliers:

$supplier_ids = Supplier::where('supplier', $itest_supplier)->pluck('supplier_id');

Solution 2:[2]

if you want to get the id of suppliers that match your $itest_supplier

then

$supplier_id=Supplier::where('supplier', $itest_supplier)
->select('id')
->get();

but if you want to get suppliers with simliar name you could use like

$supplier_id=Supplier::where('supplier','like','%'. $itest_supplier .'%')
->get();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Lewis
Solution 2 eraufi