Quick Tips

How to Change Date Format in Laravel and jQuery UI DatePicker

One of the most often things to change in web-projects is adapting it to a certain geographical area - language and timezones are two examples. But also there's a date format, which can be pretty different in certain parts of the world. How to handle it properly in Laravel?

How to (Easily) Create a Custom Validation Rule

For some reason, only now I've found out about a feature that was introduced in Laravel 5.5 - artisan command that makes your validation rule, similar to Request classes. Let's see it in action.

How to Save User’s Last Login Time and IP Address

Quick tip of the day. Default Laravel Auth comes with User table and model, but without logging capability, so we need to build it ourselves. Fortunately, it's very easy, I will show you one method.

Laravel JSON-based Translations with Underscores __() Function

Not sure if you've noticed, but Laravel 5.6 make:auth is generating Blade files with translation-ready texts, so instead of just "Login" you will see {{ __('Login') }}. How does it work and what's the reason?

How to check access to Laravel project by IP address

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?

How to avoid TokenMismatchException on logout?

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?

Filter Eloquent relationships “on-the-fly”, when you need 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.

Redirect after Login or Register: Add your own Method

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.

Stop checking if record exists: Eloquent methods OrCreate and OrNew

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.

Eloquent Relations: how to order topics by newest posts?

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?

STAY CONNECTED

1,652FansLike
4,727FollowersFollow
5,308SubscribersSubscribe

NEWEST VIDEOS

RANDOM ARTICLES