Questions tagged [laravel-models]

91 questions
6
votes
1 answer

How to extend PHP Laravel model's fillable fields in a child class?

I try to extend an extintig ˙PHP` Laravel model with some other fields, but I not found the right solution. I use PHP 7.1 with Laravel 6.2 Here is my code, what explain what I want to do. The original model:
netdjw
  • 5,419
  • 21
  • 88
  • 162
4
votes
2 answers

How to merge child key pairs to parents in Laravel models

Old PHP user here but new to Laravel, I need help(answers or link to related solution)... If I have a relation model(or collection, I get confused here)... $data = MyData::with('new_data')->first(); resulting with... data = { a: 1, b: 2, …
Jacobski
  • 741
  • 6
  • 10
4
votes
1 answer

Cannot test laravel livewire model hidden attribute with assertSet

I have a simple LIvewire component consisting of a form to create a new User, and it work, i can tell since i've been asked to write tests after the project already reached staging. The Livewire component use a new User instance (non presisted, i.e.…
fudo
  • 2,254
  • 4
  • 22
  • 44
3
votes
3 answers

Laravel - Show name instead of id

I am trying to write some code, that displays data from a database in Laravel. But I have two table values linked to eachother with a foreign key, and when I try to show that on my page, it just shows the id and not the actual name. I saw in another…
Mauro
  • 342
  • 3
  • 10
3
votes
2 answers

Laravel 8 : How to create a Pivot Model with its associated migration?

I would like to create a model: FormsUser and the migration: forms_user To use the table as a pivot because I have problems when I create a forms I am told that the table: 'forms_users does not exist' because I created the migration separately…
3
votes
3 answers

Pluck and Implode Method in Laravel?

I have three classes Student, Session and student classes it has a relationship (Student with Enrollment, Session with Enrollment and student Class with enrollment), when I do echo it show the…
2
votes
2 answers

Use Explicit or Implicit Model Binding on Routes in Laravel Package

I am migrating some app functionality into a Laravel package. The package includes Models, Controllers and routes. I am using Laravel 9 Everything is working except my Models are not biding to the routes so the models are not being automatically…
2
votes
0 answers

Laravel Livewire Model set default value

I have a table that I am generating through an iterative loop. The issue is that there is an input field of type date. When I try to attach my livewire model, it doesn't show the value coming from the database.
DIGITAL JEDI
  • 1,672
  • 3
  • 24
  • 52
2
votes
1 answer

Laravel Model: boot on trait and model

I have some Laravel models using the next Trait which is calling the model's boot method:
chuysbz
  • 1,262
  • 6
  • 18
  • 47
2
votes
0 answers

How to return the data of another model instance model by using joins in laravel?

I want to return the data of Charge instance instead of User , for that i am trying to use joins ,can you please help me to acheive this thing $id=Charge::whereNotNull('created_by')->get('created_by')->toArray(); foreach($id as $name){ …
usersuser
  • 167
  • 12
2
votes
0 answers

How to pass argument in third relationship, When we get the value from second relationship?

We get one relationship. Now we set conditions on relationship to get status and check one by one with each case. After getting the status type, the value of status type will pass to another relationship. how can we do this? Here is an example…
2
votes
0 answers

Laravel - How to use Auth user inside the global scope

I want to use Auth user in the global scope User.php public function scopeActive($query) { return $query->where('accessed_id', auth()->user()->accessed_id); } protected static function boot() { parent::boot(); …
Mdr Kuchhadiya
  • 431
  • 4
  • 12
2
votes
0 answers

Assert laravel model observer's event fired in PHPUnit

I'm going to write some tests for my laravel 7 controller methods (endpoints) to be sure that they fire model observer event (for example saved event on Product model) as you now model observer events do not fire while using mass update and it's…
SoheilYou
  • 907
  • 5
  • 23
  • 43
2
votes
1 answer

Laravel Eager Loading on a single injected model

I'm trying to use Laravel Eager Loading in my project and I have read the documentation about it. Every example in documentation is about getting all instances of a model with Eager Loading. But is it just about getting all instance not just a…
Artin GH
  • 546
  • 2
  • 10
  • 21
1
vote
1 answer

Laravel relationship where clause returns all records parent

I have three tables, File, FileFolder and Folder. These tables all have their own Laravel Model, with their respective names. File FileFolder Folder Now, I need to retrieve all files that are in folder 1. Our project already contains an Eloquent…
daveyvdweide
  • 102
  • 1
  • 10
1
2 3 4 5 6 7