From time to time I see a need of restricting the access to a website by IP address, whether it’s local network or a particular set of specific computers, like home/office. What’s the best way to do that in Laravel?
We’ve just released a first “alpha” version of a package called ThemeDownloader – need your opinion, feedback and requests for future improvements. Basically, you can get a Bootstrap-based front-end theme into your Laravel project, just by launching one Artisan command.
If you stay too long on one form or get away from your computer, and then go back to fill it in – you may get a TokenMismatchException, because the CSRF token won’t be the same. It kinda makes sense, but the problem I recently discovered that it does the same for logout (which is also a form). And that’s pretty silly, so how to avoid it?
I find more and more Eloquent functions that are rarely used, so continue posting these short tips on the blog. Here’s the next one.
In Laravel’s Auth system you can customize a few most important things – one of them is a variable $redirectTo – where to take the user after login/registration. But there’s even more to customize.
Another “hidden gem” of Laravel which is surprisingly rarely used or even known, though it’s mentioned in the official Eloquent documentation. Imagine that you have a record, and you need to check if that record already exists in the database – to prevent duplicate, you wouldn’t save it second time. There’s an elegant way to perform it in Eloquent.
Quite a typical scenario, but not easy to find the answer. You can easily order Eloquent results by some column, but what if you want to order by related column in child table? Most common example is a forum like Laracasts which shows topics in order by the latest post in that topic. How to do that?
Laravel has a great database migration mechanism, but there are some things missing there. For example, what if you want your IDs start with some number, like 140001, 140002 etc?