Laravel developers tips

Helpful solutions for Laravel framework developers

Laravel

Data transformations in Laravel using collections and helper functions

December 28, 2016 by Marcin Nabiałek / Leave a Comment

When developing not trivial application it often happens that we need to make some data transformations. Let’s assume we we have user and address and we create API and want to data come in the following format:

Data format
1
2
3
4
5
6
7
8
9
[
  'name' => 'John',
  'surname' => 'Doe',
  'address' => [
     'street' => 'Street',
     'zipcode' => '23123',
     'city' => 'Some city',
  ]
]

but in database we don’t want to create separate table and put address fields in user table … [Read more…]

Posted in: Laravel, PHP, Request Tagged: array_dot, array_set, collections, data transformation, keyby

How to install Laravel 5 application in different versions

August 24, 2016 by Marcin Nabiałek / 7 Comments

Laravel 5.3 framework has been just released. I won’t focus on new features about it right now, I will just make it clear how to install different versions of Laravel without a problem as for many especially new developers it causes problem. As Composer is standard for installing dependencies let’s use this method to install … [Read more…]

Posted in: Composer, Laravel, PHP Tagged: branch, installation, project

Partial mocking and issues you don’t expect

June 30, 2016 by Marcin Nabiałek / 2 Comments

As we all know, writing tests is very useful when developing applications. But sometimes you might find issues when writing tests that are really hard to detect. If you ever got “Serialization of ‘Closure’ is not allowed” / “unserialize(): Error at offset 0 of 186 bytes in” errors when running PhpUnit together with Mockery – … [Read more…]

Posted in: Laravel, Mockery, PHP, PhpUnit, Testing Tagged: exceptions, issues, mocks

How to trim input in Laravel

June 26, 2016 by Marcin Nabiałek / 4 Comments

When you want to validate Laravel input, you can do it out of the box using for example Form Request class. Let’s assume you want to allow creating tags. Each created tag should have at least 3 characters. Simple? Well, it looks really easy, but when we look at details, we can find a few … [Read more…]

Posted in: Laravel, Request, Validation Tagged: input, trim
« Previous 1 2

Marcin Nabiałek

Marcin Nabiałek - Certified Laravel Developer
Marcin Nabiałek - Zend Certified PHP Engineer

Categories

  • Composer
  • Eloquent
  • Laravel
  • Laravel Blade
  • Laravel Dusk
  • Laravel packages
  • Mockery
  • PHP
  • PhpUnit
  • Request
  • Testing
  • Validation

Copyright © 2021 Marcin Nabiałek