Home > Blockchain >  How to select one value from MySQL table row laravel
How to select one value from MySQL table row laravel

Time:09-01

Database image

how can i get one value from bank_id row ?

i have two table...one is bank name with id other is state with state name and bank_id(equal with bank table) state table's bank_id every row have multipal value..like 1,2,3 or 9,5,7 my question is how can i get all state name where bank id ?

please help me..

mycontroler.php

     public function getState(Request $request)
     {


  $states = DB::table("states")
    ->where("bank_id",$request->bank_id)
    ->pluck("name","id");
    return response()->json($states);

}

CodePudding user response:

Try this

  $states = DB::table("states")
    ->where("bank_id",$request->bank_id)
    ->get();

CodePudding user response:

Acording laravel documentation:

$states = DB::table('states')->where('bank_id', $request->bank_id)->get();
  • Related