Skip to content
Advertisement

Laravel – Use a column from a model relation

in my livewire view i get all the credits from their respective owners through the model relationship between clients and credits

Model: Client

JavaScript

Model: Credit

JavaScript

in my livewire view I have a foreach that gets me all the clients, inside a switch that counts the credits of the clients

Livewire: Show-client

JavaScript

So far everything is fine, it tells me the credits and tells me if it has or not.

now the credits have the option to place them as active or liquidated

How would I make my switch, instead of telling me all the client’s credits, only take the active or in this case the ones with the number 1 and add the active credits

sorry for my bad english

Advertisement

Answer

I believe you are looking for what’s called “local query scopes” : https://laravel.com/docs/9.x/eloquent#local-scopes

JavaScript

Usage :

$clients = ...->isLiquidated()->...;

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement