Laravel Community Tools by Tighten

chad d

Joined: 12 years ago
Total tricks: 6
Last trick: 11 years ago

Submitted tricks

I spent a good hour trying to figure out why my Eloquent relationship wasn't working when I found out it was because of the difference between `$model->relationship->value` and `$model->relationship()->value`.
chadwithuh... 12 years ago 109792
When you want to check a Hashed value generated by `Hash::make()` you need to use `Hash::check('unhashed', $hashed)`. Every time you run `Hash::make('string')`, a different hash is made and will not match the previous one.
chadwithuh... 12 years ago 29106
4.0
There are a few tips already for active states on navigation, however none are based on Route names. I prefer to use Route names for all routes, so here is a modified version of the "active states" trick for route names.
chadwithuh... 12 years ago 12894
Creating a form macro is very easy and awesome for creating your own UI elements. The original downside I found was losing the automatic model binding from Form::model(). A user on StackOverflow helped solve the problem for me.
chadwithuh... 12 years ago 10154
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 25364
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... 11 years ago 31121