Questions tagged [laravel-models]
91 questions
1
vote
1 answer
How to get conversation of given users (using where condition twice on same column)?
I am trying to create a chat app in Laravel. When a conversation is created between users, I don't want to record a user as host user. I would like to get a conversation filtered by given users. Example: If USER_1 and USER_2 belong to…

mg tint
- 23
- 3
1
vote
1 answer
How to resolve Not unique table/alias error in laravel?
I am very new to the laravel,i am using l5-repository package for orderBy and sortedBy to sort columns ,while hitting API i am getting following error please help me to resolve the issue
my API URL…

usersuser
- 167
- 12
1
vote
0 answers
Laravel multiple polymorphic relationship
I have a database tables as followed
Posts Table
Comments Table
Users Table
Pages Table
Likables…

drhtoo
- 11
- 2
1
vote
1 answer
Find which model method is triggering the Event
I'm using Laravel's Event & Listener functionality to detect the following model actions and trigger some application logic.
app/models/MealFood
/**
* The event map for the model.
*
* Allows for object-based events for native Eloquent events.
*
…

shAkur
- 944
- 2
- 21
- 45
1
vote
1 answer
Null Relation in Laravel Model
These are my Migrations
Type Migration
Schema::create('digital_types', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
Content…

CC7052
- 563
- 5
- 16
1
vote
1 answer
2 foreign keys referencing same primary key laraavel
I'm relatively new in Laravel and I would like to learn how to create recursive relation with 2 foreign keys referencing the primary key.
I have table item_associations which has 2 FK referenced to the item table's…

Amir Adamov
- 43
- 3
1
vote
2 answers
I have a belongs to relationship in laravel 8 and it returns null when I am trying to use that relationship in the tinker shell
I am using Laravel 8 and I have the following very simple models and migrations,
Author Model

gfit21x
- 141
- 9
1
vote
0 answers
Polymorphic relationship inside application Laravel Eloquent
In my application, I need the tables users and companies, which will have a one-to-many relationship where the user hasMany companies. Now I'll need to add roles here where a user can have multiple roles inside a company.
User1 will have role1,…

memeister
- 53
- 5
1
vote
2 answers
Whenever I use Laravel resource with paginate method, I get a response with "links" and "meta" keys. I want to change these keys to a new format
I used laravel resources for my api responses and added paginate method. Upon using paginate method I always get a result like this where laravel by default gives three keys namely "data", "links" and "meta". But I want to change the resource to my…

Mostain ahmed
- 33
- 1
- 9
1
vote
2 answers
parent id for category and subcategory
I use L8 And I have a category table ,it has parent_id for my subcategories
categories table
Category model
categoryController
SubCategoryController
categories.blade
sub_categories.blade
In my subcategory-index.blade.php I want to show categories…

calisa
- 175
- 1
- 4
- 17
1
vote
1 answer
Laravel 7: Connect 3 tables using models
I have three different tables:
Users: ID, name, etc...
Teams: ID, creator_id, etc...
Team_Action: ID, team_id, etc...
Permissions: ID, name, etc...
Team_Action has a FK (action_id) with Perimissions which I need the name value of that…

George G
- 93
- 7
1
vote
1 answer
Laravel ManyToMany relationship Is reversing tables names
i need to make the post accepts as many language as i need so i have tow models post and language
in post model:
public function languages(){
return $this->belongsToMany(\App\Models\Language::class);
}
in my language model :
public function…

derar sattouf
- 69
- 2
- 9
1
vote
1 answer
best way to retrive a collection from -many to many- connected to -one to many- relation (laravel7)
you can see a part of my database in the image below:
the goal of this design was to able the admins send alerts to users filtered by center and field(dynamically). if you think this is a bad design tell me (please say why and how should I improve…

Mohammad Hossein
- 404
- 7
- 21
1
vote
2 answers
PhpStorm autocomplete with \Nwidart\Modules
The problem would be that I use PhpStorm IDE. The Laravel project is managed by nwidart/laravel-modules.
However, PhpStorm does not handle basic Laravel functions. For example: findorfail(), for own models:
Method 'findorfail' not found in…

Cappsy
- 61
- 6
0
votes
0 answers
Should i write migrations every time i want to create table in Laravel?
So basicly i have started working with laravel. And to this moment i have been writing migrations and defining the fields there. And after that i should create a model related to it and define the relationships there. Unlike the Django framework…

p1rate_k1ng
- 1
- 2