Laravel Community Tools by Tighten

Tag "4.0" tricks

68 tricks
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 11 years ago 10570
4.0
Sometimes you want to paginate a table in an order, but when showing the items you need to reverse the order. Using the array_reverse on Paginator wont work, but if you use the getItems() its possible.
diegofelix 11 years ago 10021
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 41202
For one of my projects I needed to get an ID of the previous and next record in the DB. This could go well with portfolios, orders, blog posts, all kinds of things where you need to display next/previous entry links. Let’s say we are logged in as an admin and we are on this user’s page and we want to see next/previous user’s id. The following Eloquent code makes it easy to do that. Enjoy!
msurguy 12 years ago 17131
Using of the Bootstrap Error classes for flash message, one simple helper would help to simply to extend the flash messages.
yoosuf 12 years ago 17717
If you have datetime fields lets say, last_updated or registered_at, this is a nice trick to make laravel know about that fields & let it know. Just overwrite Eloquent's constants.
kbirmhrjn 12 years ago 8477
Route::filter() passes multiple filter params as individual values like function($route, $response, $param1, $param2 ...) this is an easy way to check against multiple params. If I'm checking permissions like this ->before('permission:user,moderator') this makes it easy to check against. Since Route::filter() passes $route and $response in a BEFORE filter the array_slice strips them out of the array to allow you to check against the values you want.
bgallagh3r 12 years ago 8472
Inside my seeders I often use this trick to prevent from re-seeding already present values. For example, if you are creating a base seed of production data -- say a pre-defined list of values -- and add a new item but do not want to delete all seed data and re-seed, you can try this. Note that, there are some flaws to it. Such as: It will not delete missing values if your new list has changed, or if you set the attributes too specific, you may end up creating a duplicate (for instance, if you have the same item with different `order` values due to rearranging in the list).
chadwithuh... 12 years ago 25451
Avoid casting views to strings. If your view contains an error, casting with `(string)` will cause a less-than-helpful exception to be thrown, pertaining to throwing an exception within the view's `__toString()` method. Use `View::make()->render()` instead.
kwoodfrien... 12 years ago 23320