Category : join

There’s a table in my SQL DB called "projects" and it has a column in it "categories" which is a varchar(255) representation of a php array "[‘category_1’, ‘category_2’, ‘category_3′]" and what i’d like to do is put these categories into a separate table which would be made of a unique integer id in addition to ..

Read more

$users = DB::table(‘users’) ->join(‘course’, ‘users.id’, ‘=’, ‘course.courseId’) ->join(‘skills’, ‘users.id’, ‘=’, ‘skills.id’) ->join(‘subjects’, ‘users.id’, ‘=’, ‘subjects.id’) ->get(); dd($users); This gives me an empty result like this- items: []. I would like to join the 4 tables – users, course, skills & subjects and fetch all the datas in all the 4 tables. users table has the ..

Read more

I have StudentEducation model and in this model i got public function student_education_countries() { return $this->hasMany(StudentEducationCountry::class, ‘education_id’); } and public function student_education_education_types() { return $this->hasMany(StudentEducationEducationType::class, ‘education_id’); } in StudentEducationCountry model i got public function student_education() { return $this->belongsTo(StudentEducation::class, ‘education_id’); } public function student_country() { return $this->belongsTo(StudentCountry::class, ‘country_id’); } and in StudentEducationEducationType model i got public ..

Read more

i want to have all the records from district table even if there is no match in cases table in following query $object = DB::table(‘case_details as cd’) ->select( DB::RAW(‘SUM(cd.registered) AS registered’), "prv.$name AS province","crt.$name AS court", "dis.$name AS divan","c.court_id","c.divan_id" ); ->leftJoin(‘cases AS c’,’c.id’,’cd.case_id’) ->leftJoin(‘provinces as prv’,’prv.id’,’=’,’c.province_id’) ->leftJoin(‘courts as crt’,’crt.id’,’=’,’c.court_id’); ->rightJoin(‘districts as dis’,’dis.id’,’=’,’c.district_id’); $object = $object->groupBy("dis.id"); ..

Read more

this my Controller public function reporting() { $monthly_report = DB::table(‘monthly_report’) ->join(‘sita_invoice’,’sita_invoice.id_sita’,’=’,’monthly_report.id_sita’) ->join(‘traffic_log’,’traffic_log.id_aircom’,’=’,’monthly_report.id_aircom’) ->get(); return view(‘traffic.report’, compact(‘monthly_report’)); } but not getting any data from other tables Sourc..

Read more

To quickly summarize, my first table’s rows gets multiplied by the amount of rows in the second table possibly due to my join: Table 1:(bbr_group) I only have two rows 1 Table 2:(bbr_group_type) I only need to get group_type_name, joined by group_type_id 2 Controller: public function fetchgroup(){ $all_groups = HmsBbrGroup::join(‘hms_bbr_group_type’, ‘hms_bbr_group.group_type_id’, ‘=’, ‘hms_bbr_group.group_type_id’) ->orderBy(‘group_id’, ‘ASC’)->get(); ..

Read more

I need help with this query, $data_query->leftJoin(‘categories as parent_category’, ‘invoice.category_id’, ‘=’, ‘parent_category.id’) ->leftJoin(‘categories as child_category’, ‘parent_category.id’, ‘=’, ‘child_category.id’) ->whereRaw("concat(parent_category.name,’/’,child_category.name), ‘like’, ‘%".$filter."%’"); I am getting this error "Column not found: 1054 Unknown column ‘parent_category.name’ in ‘where clause’ at /home…" and I understand what it means, but don’t know why I am getting it. Any advice on ..

Read more

im working on a join/find laravel DB to retrieve te correct data, but it is showing the last entry of the database repeated 13 times. I hope you can help me. Here is the code. in controller $joinCot = Cotizaciones::findOrFail($id); $joinCot = DB::table(‘cotizaciones’)->join(‘prod_cotizaciones’, ‘prod_cotizaciones.id_cotizacion’, ‘=’, ‘cotizaciones.id’) ->join(‘users’, ‘users.id’, ‘=’, ‘cotizaciones.id_usuario’) ->join(‘clientes’, ‘clientes.id’, ‘=’, ‘cotizaciones.id_cliente’) ->select(‘cotizaciones.id’, ..

Read more

i feel too difficult when trying to fix this. i want to update my existing data. heres my laravel code: public function updateakun() { $user = User::leftjoin(‘sosmeds’, ‘users.id’, ‘sosmeds.user_id’)->find(request(‘id’)); $user->name = request(‘nama’); $user->email = request(’email’); $user->username = request(‘username’); $user->bio = request(‘bio’); $user->ig = request(‘ig’); $user->update(); return response()->json([ ‘success’ => true, ‘message’ => $user, ]); } ..

Read more

I’m using a made up scenario, but facing similar issue. I’m using Laravel 8 and have two models Family & Centre. Both containing common column name id. In model Family I want to restrict families data based on centre of user logged in. For now I’m hardcoding it a dummy centre_id Below is my booted ..

Read more

my database tables One is Categories with (Id, name) 2nd is Blog with (id, post, img) 3rd is Blog_category with (id, blog_id, category_id) query I’m using $blogs = Blog::join(‘categories’, ‘blog_categories.category_id’, ‘=’, ‘categories.id’)->orderBy(‘created_at’, ‘DESC’)->get(); return response()->json($blogs, 200); error I’m getting SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘blog_categories.category_id’ in ‘on clause’ (SQL: select * from blogs ..

Read more