Category : relational-database

I made many to many relationships for admin and school tables. "SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘admin_id’ in ‘field list’ (SQL: insert into admin_school (admin_id, school_id) values (91, 2))" Table : admins schools admin_school (pivot table) Here is structure pivot table Model Admin public function schools(){ return $this->belongsToMany(‘AppModelsSchool’, ‘admin_school’, ‘admin_id’, ‘school_id’); } Model ..

Read more

I want to do change「with」 method by 「where」. like this. User::where(〜)->with(‘post’)->orWhere(…)->with(‘post2’)->paginate(10) For example(This example is not work. This is for image) $user = User::Where(function ($query) use ($id1, $id2) { $query->where(‘user_id’, $id1) ->whereIn(‘monster_id’, $id2) ->with([‘user’ => function ($query) { $query->with(‘residence’)->get(); }]); })->orWhere(function ($query) use ($id1, $id2) { $query->where(‘monster_id’, $id1) ->where(‘user_id’, $id2) ->with([‘user2’ => function ($query) { ..

Read more

Message Tables Column is | messages_id(pk) | user_id | target_id | message | created_at User_id has sender user’s id. Target_id has receiver user’s id And simple user table has relation to MessageTable by HasMany. public function message() { return $this->hasMany(‘AppModelTableModelMessage’, ‘user_id’, ‘user_id’); } I want to get Userdata and each last message from user_id=[1,2,3,4] to ..

Read more

I have an One-to-One relationships Between the user (penggunas) table and the role table, but when I access it in the controller it returns null and column not found Route.php Route::get(‘/test’, ‘[email protected]’); PenggunaController.php use AppPengguna; class PenggunaController extends Controller { public function index() { $pengguna = Pengguna::find(3); return response()->json([ ‘data’ => $pengguna ]); } } ..

Read more

I’m producing an online school platform and in part of it student can see it’s classes with their informations..but the related function return this error : Undefined offset: 0 (View: C:xampphtdocsOnlineSchoolresourcesviewsadminstudentClassReport.blade.php) there are some relations between models My Models: USER(students and teachers) ، LEVEL(level of classes) ، Classroom. => there is a many to many ..

Read more

I have meals model which look like these class meals extends Model { use HasFactory; protected $appends = [ ‘image_full_path’, ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ ‘name’, ‘text’,’price’,’image_url’,’rating’,’discount’,’sub_catogry_id’ ]; public function sub_catogry() { return $this->belongsTo(‘AppModelssub_catogry’); } public function order_meal_list() { return $this->hasMany(order_meal_list::class); } ..

Read more

I have 4 tables Packages: id name Tests: id name subcategory_id category: id name parent_id = 0 // if main category packages_tests:(pivotTable) id package_id test_id I want to get tests inside each package with category like that packages: [ name: package1 categories: [ { name: mainCategory1 tests: [ {test1}, {test2} ] }, { name: mainCategory2 ..

Read more

I have two Models (Store, Product) and Relationship hasMany public function products(){ return $this->hasMany(Product::class); } And I want to return response collection, in class StoresCollection extends ResourceCollection public function toArray($request) { return $this->collection->map(function ($item) { return [ ‘id’ => $item->id, ‘seller_id’ => $item->seller_id, ‘store_product’ => $item->products()->get(), ]; }); } But I don’t want to return ..

Read more