Home > OS >  Laravel I need to select Id where supplier name are similar
Laravel I need to select Id where supplier name are similar

Time:04-07

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

CodePudding user response:

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');

CodePudding user response:

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();
  • Related