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
Tag: eloquent
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
One-To-Many Relationships in laravel eloquent
Good morning, I am having a little trouble with model relationships in Eloquent, I need to link articles and images for those articles with an intermediate table. In the intermediate table I’d like to add the id’s of both article and image, and I would like to retrieve all the images belonging to an article, what would be the best
Laravel Eloquent, group by month/year
i’m trying to group my data by month and year. The output is : if i group only by month, i don’t know from which year belong this month, my expected output is : i want to do it in sql, not in php. Answer You can try as:
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 posts from user with users post table
I searched a lot but could not find any answer about it, so I hope you could help me! I have three tables: posts, users and post_users. Post_users contains two columns: user_id and post_id. I need to get all posts by an user with Eloquent. Any ideas? Answer Model User: Model Post: Try:
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 5.2 – Selecting only articles that has comments
I built a commenting system, and I’m working on a page that shows all the comments that are waiting for approval. The relationship: Article.php public function comments() { return $this->…
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