Author: Povilas Korop

Crossroad

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.

Thursday, December 28th, 2017

new-record

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.

Wednesday, December 27th, 2017

laracasts

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?

Wednesday, December 27th, 2017

auto increments laravel migrations

How to set auto-increment start in Laravel migrations?

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?

Monday, December 18th, 2017

Feature-Request

Differences: $request->get() vs $request->input() vs request() vs get_data()

How do you handle POST data in your store() or update() methods? Seems like a simple question, but actually there are so many options!

Wednesday, November 29th, 2017

quick-start

Quick Start with Laravel 5.5 + Vue.js: Simple CRUD Project

Vue.js is getting more and more popular, and good thing about it that it’s pretty quick to get started with. Let me show you an example in this tutorial and sample project.

Thursday, October 26th, 2017

pagination

Laravel simplePaginate: more effective with bigger data

Laravel pagination is quite a simple thing to use, but to determine the amount of pages it makes additional query to the database, which may be a problem for bigger amount of data. And you can actually avoid it.

Tuesday, October 24th, 2017

chunks

Laravel Blade foreach “trick”: splitting results into chunks

Imagine a situation that you have 10 records to show in Blade but you need to show them in 2 sections, five records each. There’s a pretty nice trick how to do that in @foreach loop.

Wednesday, October 18th, 2017

random data

Laravel: Two Ways to Seed Data with Relationships

While seeding data, it’s common to have one class for each database table. But what if there are relationships? I

Monday, October 16th, 2017