Skip to content
Advertisement

Tag: eloquent

Laravel custom db driver

i know there is a nice way of defining connections via app/config/database.php . But i don’t think there is a driver for me available. Imagine my db is read from file, like a txt. (Yeah! that’s my client db, sort of). So in that file, before I i need a real driver! Currently it uses a txt base db but

Laravel Carbon Group by Month

Can anyone see what I’m doing wrong? I’m trying to output all the months but group them so they are unique. I’m getting the following back In my database I have five news articles all created_at 05/01/2017 so it’s right that I only get one response but I’m not getting the number of the month back? Answer You can use

Laravel – Eloquent – Dynamically defined relationship

Is it possible to set a model’s relationship dynamically? For example, I have model Page, and I want to add relationship banners() to it without actually changing its file? So does something like this exist: Or something similar? As they are fetched using the magic methods anyway, perhaps I can add the relationship dynamically? Thanks! Answer I’ve added a package

Laravel Eloquent – get last insert of related model

I have a relationship between two models: Terminal and terminalRent. A Terminal can have many terminalRents. I want to get the last Rent for a specific Terminal. When using where() it will reflect those on the Modal hoewever I want to get the last record for terminalRent in relation to the specific terminal. $id is the Id of the terminal

Type hinting for the model objects of Eloquent ORM

I haven’t used laravel yet, but watching the tutorials on youtube left me with a question to type hinting, that is really important to me. Now I have read here Type Hinting Eloquent Models and here Eloquent ORM Code Hinting in PhpStorm but neither addresses the following problem: now lets say movie has a name, id, length, author all those

Laravel Eloquent where field is X or null

I have a table like this: Now I want to get all entries where field1 is 1, field2 is null and where datefield is smaller than X or null. I already tried something like this: but thats not working. I always get every entry where datefield is null. It doesn’t matter what the other fields are. I also tried to

Advertisement