Category : relationship

I have 3 tables Company->ManyToMany->Activity->BelongsTo->chamber i need to use HasmanyDeep to find all chambers related to specific company. when i write this in Company Model, it returns empty public function chambers(){ return $this->hasManyDeep(‘AppModelsChamber’,[‘activity_company’,’AppModelsActivity’],[‘activity_id’,’company_id’],[‘chamber_id’]); } Sourc..

Read more

I asked this question before, but formatted it way different and incorrectly. The deal is, I have 4 tables of which I would like to nest. I want Measurement containing measurement_data which contains measurement_fields which contains measurement_type (only showing important fields). So far, I have everything but MeasurementFields inside of Measurement Data. My tables: measurements ..

Read more

I have three models. Sponsor, Optin and Participant. Sponsor has a one-to-many relationship with Optin and Optin has a one-to-one Participant. Which make the models look like this: Sponsor model class Sponsor extends Model { public function optins() { return $this->hasMany(Optin::class); } } Optin model class Optin extends Model { public function sponsor() { return ..

Read more

I have three models that are related: Article, ArticleBlock, ArticleBlockImage ArticleBlock is related with Article and ArticleBlockImage is related with ArticleBlock Here are the relations Article public function article_blocks() { return $this->hasMany(‘AppModelsArticleBlock’); } ArticleBlock public function article() { return $this->belongsTo(‘AppModelsArticle’); } public function article_block_images() { return $this->hasMany(‘AppModelsArticleBlockImage’); } ArticleBlockImage public function article_block() { return $this->belongsTo(‘AppModelsArticleBlock’); ..

Read more

I use Voyager admin interface (v.1.4) for Laravel (v8.0). Voyager supports multiple languages (official documentation: https://voyager-docs.devdojo.com/v/1.4-1/core-concepts/multilanguage). I have this relationship: Process belongsToMany WorkMachine Process hasMany Product Process model: <?php namespace AppModels; use IlluminateDatabaseEloquentModel; use TCGVoyagerTraitsTranslatable; class Process extends Model { use Translatable; protected $translatable = [‘name’, ‘meta_description’, ‘description’]; public function get_workmachine() { return $this->belongsToMany(WorkMachine::class, ‘process_workmachine’); ..

Read more

We are getting latitude and longitude on 3rd level due to which the filter in below query is not working in Laravel //Filters Form Nearest location with latitude and longitude. `if($request->latitude !="" && $request->longitude !="") { $list = $list->whereHas(‘partnerOutletPromotion’, function ($query) use ($request) { $query->select(DB::raw("*, 6371 * acos(cos(radians(‘".$request->latitude."’)) * cos(radians(latitude)) * cos(radians(longitude) – radians(‘".$request->longitude."’)) + ..

Read more

Hello Guys, I am just passing my query to notification blade, but its gave error. I dont know what i did wrong with bellow code. If you guys fix this issue i will be very glad. Thanks in advance Notification seen model <?php namespace AppModelsBackend; use IlluminateDatabaseEloquentFactoriesHasFactory; use IlluminateDatabaseEloquentModel; class notificationseen extends Model { use ..

Read more

I’m using Laravel v8 I have 3 models as:Family, FamilyMember, FamilyRelationship Family table: id address created_at updated_at 1 test NULL NULL Family Relationship table: id name created_at updated_at 1 Head NULL NULL 2 Spouse NULL NULL 3 Child NULL NULL Family Member table: id first_name last_name family_id family_relationship_id 1 John Doe 1 1 2 Jane ..

Read more

I am doing a laravel api with custom permissions feature. This is my structure of tables: User id | email | password Company id | companyName Permissions id | name User_has_permissions user_id | company_id | permission_id I am get the user and permissions with code below in model: public function permissions() { return $this->belongsToMany(Permission::class, ‘user_has_permission’, ..

Read more

I’m creating feature for order in canteen project. I have made these eloquent relationship: canteen->products product->canteen order->products order_product->product (order_product is like detail item of the order) If I want to get canteen data of the order_product, I can just type order_product->product->canteen->id. This is what I have done to show details of orders. But the lists ..

Read more

I’ve created my first composer package for Laravel 8. It provides a user group model and some routes. A couple of them are POST | api/v1/usergroups | usergroups.create | [email protected] | api GET|HEAD | api/v1/usergroups | usergroups.index | [email protected] | api GET|HEAD | api/v1/usergroups/{usergroup} | usergroups.show | [email protected] | api PATCH | api/v1/usergroups/{usergroup} | usergroups.update ..

Read more

I am trying to figure out how to implement related posts to a post. There is an article which can have multiple colors. Each color is an article by itself. So lets say a yellow shoe is also available in blue. Right now I have a table posts: use IlluminateSupportFacadesSchema; use IlluminateDatabaseSchemaBlueprint; use IlluminateDatabaseMigrationsMigration; class ..

Read more

I have the following tables structure for my database: users event_user events event_user_histories event_user_reviews locations My business rules are: User can select and join many events, and an event can be joined by many users. User will need to pick an event and a location to participate in the event. The event_id, location_id, user_id, status, ..

Read more

I need to map multiple "types" pointing to same model over a polymorphic relationship. This because in my application i set a laravel-permission authentication package that fails if i don’t include his model type in AppServiceProvider.php boot method. I’ve got a Resource model that has a polymorphic relationship with User model and Equipment model. Every ..

Read more

I need to retrieve the latest model in a relationship, from a collection of records that belong to a set of users. The best I’ve come up with is: SELECT `answers`.*, answers.created_at, `questions`.`survey_id` AS `laravel_through_key` FROM `answers` INNER JOIN `questions` ON `questions`.`id` = `answers`.`question_id` WHERE `questions`.`id` IN (4, 5, 6) AND `user_id` IN (1 , ..

Read more

I’ve a problem when sorts data from largest to smallest from table relations that do not necessarily have a relationship with PHP Laravel Eloquent. Table: items |—————————| | id | name | price | |—————————| | 1 | Samsung | 70.000 | | 2 | iPhone | 90.000 | | 3 | Nokia | 50.000 ..

Read more