0

I have 1 table data . and I have function edit on this table . in this edit form I have select dropdown to show pluck from database . I have 3 table . this name is aduan, ipsrs , teknisi

struckture aduan table

id 
user_id
ipsrs_id
teknisi_id
aduan
etc.....

ipsrs table

id
nama_bagian
etc....

teknisi table

id
ipsrs_id
nama_teknisi
etc...

This is my controller :

public function index(Request $request)
{
    $ipsrs = DB::table('ipsrs')->pluck('nama_bagian','id');


    $belum_kerjakan = Aduan::with('users')->where('status','Belum Dikerjakan')->get();

    $teknisi        = Teknisi::where('ipsrs_id' , 1)->pluck('nama_teknisi', 'id'); 
    $dalam_proses   = Aduan::with('users')->where('status','Sedang Dikerjakan')->get();
    $selesai        = Aduan::with('users')->where('status','Selesai')->get();
    return view('admin.admin_dashboard',[
        'belum_dikerjakan' => $belum_kerjakan,
        'dalam_proses'     => $dalam_proses,
        'selesai'          => $selesai,
        'ipsrs'            => $ipsrs,
        'teknisi'          => $teknisi,
    ]);


}

Example this variable $belum_dikerjakan is showing table data and I have fucntion edit on this table ( in modal) .

But this I don't know how to catch data (ipsrs_id) to set where clause in the pluck . I want to change 1 to ipsrs_id form table , but how ?

llinvokerl
  • 1,029
  • 10
  • 25
Adhik Mulat
  • 538
  • 2
  • 10
  • 39

2 Answers2

0

If I understood the problem then here is the answer

pull only the ids from ipsrs table and pass to Teknisi table whereIn method

$ipsrsIds = DB::table('ipsrs')->pluck('id')->toArray();

$teknisi = Teknisi::whereIn('ipsrs_id' , $ipsrsIds)->pluck('nama_teknisi', 'id'); 
Albert
  • 174
  • 4
  • 16
  • this output ipsrs_id is just '1' , but if i use where in this query will show like this , (SQL: select `nama_teknis`, `id` from `teknisi` where `ipsrs_id` in (1, 1, 1, 1, 1, 2)) i remove 1 character to show result query . – Adhik Mulat Jan 11 '20 at 02:39
  • but if i only use where this is showing : (SQL: select `nama_teknis`, `id` from `teknisi` where `ipsrs_id` = 1) – Adhik Mulat Jan 11 '20 at 02:39
0
public function edit($id)
    {
        $category =Category::findOfFail($id);
        return view('admin.category.edit',compact('category'));
    }


public function update(Request $request, $id)
    {
        $this->validate($request,[
            'name' => 'required|unique:categories'
        ]);
        $category = Category::find($id);
        $category->name = $request->name;
        $category->slug = str_slug($request->name);
        $category->save();
        Toastr::success('Category Successfully Updated','Success');
        return redirect()->route('admin.category.index');
    }