dimanche 30 décembre 2018

How to insert select and join method in query using when method?

I am using when method for search filtering with this code:

 $newitem = DB::table('itemregistrations')
                ->when(request('umur'), function($query){
                    $query->whereRaw('YEAR(CURDATE()) - lahir_yy >= ?', [request('umur')]);
                })
                ->when(request('negeri_lahir'), function($query){
                    $query->where('NegeriID', request('negeri_lahir'));
                })
                ->when(request('kategori'), function($query){
                    $query->where('CategoryID', request('kategori'));
                })
                ->when(request('pangkat'), function($query){
                    $query->where('OperasiID', request('pangkat'));
                })
                ->get();

But I need to insert join and select method to get the categoryname and operasiname. but when I insert it to the code, the query error appear.

How to use join and select method in the code?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire