Laravel Community Tools by Tighten

Recent tricks

458 tricks
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 8456
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 8452
Catch all routes and paths using the auth filter. A route validation method is added to the Users model called hasAccess($route) and returns true if the user has that route. If the user doesn't have the route the error message will inform of what access they are missing.
somadden 12 years ago 9871
To setup configuration according to each environment you can set environmental variables. In this below example I am setting up an environmental variable "LARAVEL_ENV" with below values. staging as LARVEL_ENV staging production as LARVEL_ENV production Then in start.php under detect environment add the below code for getting the environment. You can add config files under respective folders.
ashwin-sur... 12 years ago 9871
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 25394
Pull a ready-to-go array from an Eloquent model to build a dynamic dropdown in your views
dexbarrett 12 years ago 148496
We have released the source code of this website! You can check out the repository containing a mirror copy of this website: https://github.com/CodepadME/laravel-tricks to create your own websites like Laravel-tricks. It uses PSR-2 coding standards, a ton of libraries and packages and is a good resource to take a look into.
msurguy 12 years ago 9641
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 23296
Automatic adding user id. In the: First create columns into database tables with names "updated_by" and "created_by"
fhferreira 12 years ago 17933