Questions tagged [eloquent-relationship]

Official documentation: https://laravel.com/docs/7.x/eloquent-relationships

944 questions
0
votes
2 answers

How to save record in database using belongs to many relation in laravel

I have three tables: restaurant_location, cuisine_restaurant_location and cuisines. There is a list of all cuisines in my cuisines table. I have all the details of the restaurant in my restaurant_location table. A restaurant can have many cuisines…
Haris Khan
  • 335
  • 5
  • 20
0
votes
2 answers

Add Relationship result to where query

Can anyone help, I'm out of ideas. I have this code: $item = ItemsBrandOitb::select('ItmsGrpCod')->where('Brand', '=', $brand)->first(); return ItemsOitm::where('Country', $country) ->where('OnHand', '>', 0) …
0
votes
1 answer

conditional where on the basis of value of another model

I have three models Invoice Studio R_studio_pay Relationships are as follows studio hasMany Invoice studio hasOne R_studio_pay I need to get invoices->where('recurring', 'single')->get() if a column is_r is 1 in R_studio_pay else i don't want the…
sushant
  • 87
  • 7
0
votes
1 answer

Recommended eloquent relationship for two models

I apologize in advance if this question is too specific but I am having a hard time choosing the right eloquent relationship between these two models. I have two models, one named "Package" (for example a travel package) and another called…
realnsleo
  • 709
  • 2
  • 12
  • 29
0
votes
2 answers

Laravel : Eloquent HAVING returns invalid data set

I am trying to retrieve the hotel list, In which rooms available for requested dates. The room availability table looks like below. room_availability id | hotel | room | start_date | end_date | count |…
OutForCode
  • 381
  • 9
  • 26
0
votes
1 answer

Laravel and jenssegers mongodb relationship data not saving

I have 2 classes in Laravel class Company { public function people() { return $this->hasMany('Person'); } } class Person { public function company() { return $this->belongsTo('Company'); } } Now in another class, I am…
0
votes
1 answer

Laravel - Best Practice Update and Save Record to database using array of object

I want to ask about best practice how you guys do when saving and updating data to database using array of object. For example i have this AoJ: [ { package_id: 1, posts: [ {id: 1, post_id:…
ssuhat
  • 7,387
  • 18
  • 61
  • 116
0
votes
1 answer

Access relation in forelse on the same model - laravel

i have a question about accessing relation in laravel model. I have category model which has relation to translation model and category model(same model/itself - one category can be displayed in other categories using pivot table…
Marek Kaliszuk
  • 577
  • 5
  • 21
0
votes
1 answer

Problem using Eager Loading in a Eloquent Model

I have 2 models and their relations. The first class is called 'Documento': class Documento extends Model { protected $table = 'documento'; protected $primaryKey = 'cod_documento'; public function emisor() { return…
0
votes
2 answers

Laravel eloquent relation search not working properly

I am new in laravel and facing issue with eloquent search query.I have two table assets and assets_maintenance. They have relation with them which is assets hasMany assets_maintenance in asset Model assets belongsTo assets_maintenance in…
Anuj kumar
  • 26
  • 5
0
votes
0 answers

Laravel pivot relation without specify one of them

I have a table to persist all reactions available on the app (reactions) and N tables to be related to this in many-to-many relation with a pivot table. Ex: // Post Model public function reactions() { return…
fiskolin
  • 1,421
  • 2
  • 17
  • 36
0
votes
2 answers

Laravel Has Many through relationship not working

I am new in laravel and I am facing issue with relationships. I have three tables. asset assetmaintenance users id id id name asset_id name …
0
votes
2 answers

How access value of double relation in laravel 5.7? order > history > statur lang

i would like to display latest order status name from database but i have a problem with displaying data. Here is my code: OrderController class OrderController extends Controller { public function index() { …
Marek Kaliszuk
  • 577
  • 5
  • 21
0
votes
2 answers

laravel sum of Records.records.record.column in eloquent

Here is the relation transaction hasMany Carts Cart belongsTo product product->price here is the Model class //# TransactionModel public function getCarts(){ return $this->hasMany(CartModel::class, 'transaction_id','id'); } //#…
david valentino
  • 920
  • 11
  • 18
0
votes
1 answer

Eloquent hasMany with foreign key on joint table

Assume this: class List extends Model { public function items(){ return $this->hasMany(Items::class, 'c.class_id', 'class_id') ->rightjoin('items_classes as c', 'c.items_id', '=', 'items.id'); } } The problem is that…
Omid
  • 4,575
  • 9
  • 43
  • 74