Laravel Community Tools by Tighten

Category "Eloquent" tricks

140 tricks
I recently figured out that you can specify the columns that you want to select from an eager loaded relationship in Eloquent. I thought others might find this useful as I couldn't find much about this online!
stidges 12 years ago 42196
sometime we need to autocomplete one input area and based on the value of this input area we sometime populated a dynamic dropdown . I thought it worth sharing .
hassanjama... 12 years ago 35719
How to update many-to-many relationship
nihaoit 12 years ago 15175
Here is how to beat Laravel to the punch when the database isn't playing nice. The error codes are specific to MySQL. You can easily substitute the error codes for whatever DB you are using. Below are 2 common errors. Here's a scrrenshot of the error page plus.google.com/113701899574492909448/posts/c4oAn7FDmLj
DragonI 12 years ago 12121
Get a real-time view of all the currently executing queries.
mcraz 12 years ago 27529
This is a simple macro in case you need to loop through a bunch of elements, without the need to use a foreach{}. There's support for Bootstrap class names: if your template's class attribute includes col-?-?, then this macro will add a "clear" tag to the end of each row, and also add a "row" class to the wrapper. To do (in a future release): pagination, multiple devices col- classes support.
jplozano 12 years ago 10643
4.0
I've used this technique to check if I have called any `->with()` or other relations loaded on a model. I had a need for this since I have a lot of methods that require relation data in order to generate an appended property on the model. For example, if I want to pull all of the recent Posts of an Author and I want to store it on the model as `posts_this_month`, I would need to have Posts relation loaded. I want to force myself to eager load that data before I try to access it, otherwise I could run into an n+1 problem.
chadwithuh... 12 years ago 31284
Using this package - http://csv.thephpleague.com/ In your controller or wherever you are calling this method from simply create a method like so: At the top you need to use: use League\Csv; That's about it, you should be good to go! Would like to thank @msurguy for his help on this too. - See more at: http://laravelsnippets.com/members/snippets/csv-data-manipulation-with-laravel#sthash.oqBx1dzA.dpuf
lstables 12 years ago 21564
Sometimes you might want to delete/update a whole lot of items that are related to a model when a record under that model is deleted from the database. This could be useful for various scenarios when there is a lot of processing that needs to be done upon model deletion. Laravel provides model events that you can use in that case.
msurguy 12 years ago 41327