Author: Povilas Korop

Back to the future: database migrations with dates from the past

Migrations are a really useful tool to keep the database structure in sync with all environments and for all team members. And whenever we generate a new migration – its filename has a pattern of date_time_name.php. But what if you need to add a table which was in the database long time ago and created manually? How to add it into migrations folder and specify its time in the past?

Monday, August 10th, 2015

Blade Foreach: first/last item of the array

Blade templates are mostly for viewing data. But sometimes we do need to add some checks and IF-structures. One of the tricky examples – loop through @foreach but do some action only on first/last element of the array. Blade doesn’t have that functions in itself, so what do we do?

Wednesday, August 5th, 2015

How to rename users DB table in default Laravel Auth

Laravel framework comes with built-in Auth mechanism for logging-in and registering users. As a part of that we have starting migration files, one of them is creating a main Auth DB table called users. But what if we want to change that table name, and use Users for some other purpose? It’s actually pretty easy to do.

Tuesday, August 4th, 2015

Generating fake Seeds data with Faker package

If you follow proper development and deployment process, at some point you have to test your web app with some kind of data. Fake data, preferably. But, on the other hand, “real enough” to test how it would look and work. There’s an awesome package for this called Faker.

Thursday, July 30th, 2015

Eloquent date filtering: whereDate() and other methods

Let’s say you want to filter out entries created today. You have a timestamp field created_at, right? How do you filter the DATE only from that timestamp? Apparently, Taylor thought about it.

Wednesday, July 29th, 2015

How to use external classes and PHP files in Laravel Controller?

Laravel is an MVC framework with its own folder structure, but sometimes we want to use something external which doesn’t follow the same structure. Let’s review two different scenarios – when we have external class and when it’s just a .php file.

Tuesday, July 28th, 2015

Most important Laravel people to follow on Twitter

Twitter is probably the best way of getting quick updates on the news and get relevant links to newly published articles, and Laravel community is not an exception – so here’s a list of who to follow.

Monday, July 27th, 2015

Laravel Custom Validation: one of the fields required, but not both

Laravel Validation mechanism has a lot of rules provided – a field can be required, integer, IP address, timezone etc. But sometimes there is a need for a special rule which is not in that list. One example of this is when you have two fields and you need only one of them to be filled. One, or another, but NOT BOTH. Laravel doesn’t have a rule for that, so let’s create one!

Friday, July 24th, 2015

CSRF protection difference: Laravel 4.x, 5.0 and 5.1

For those who work with different Laravel versions on different projects, it’s useful to know the difference of CSRF logic – it changed a little from 4.x to 5.x.

Thursday, July 23rd, 2015