Laravel DataGrid 1.0I am happy to announce that my Laravel DataGrid package has made it to the version 1.0 🎉.This package was created with intention to make an easy to use Grid system for Laravel. The first versions (0.x) of the package used only Grid.js (which is a great, framework agnostic fronted grid package) frontend, and implemented a Laravel backend - server integration for it.This simple DataGrid worked well (and still works) for couple of my projects. We recently started a new project where it was necessary to add more features to the frontend of the DataGrid. As the fronted of...
2024-04-08 08:33:50
Laravel 10 comes with internationalization support out of the box, however when we use JetStream starter pack with Inertia the transaction support is not included in the Vue part. Luckily it is quite easy to make it work.Our use caseA brand new Laravel 10 application, using JetStream with Intertia and Vue3 frontend. The app requires multilanguage support, so we need a solution that we can use in both frontend and backend code. The best would be to use the same language files for both. In the newest Laravel (in time of writing it is version 10) we can use both...
2023-08-15 18:00:05
In agile development process it is common to use planning poker to determine the story point of the tickets. There are plenty of free planning poker apps out there, but while using those we usually had some trouble with them. Either it cannot create a new game, or it just freezed and cannot restart, or any other. What every developer thinks in these cases? Let's build our own app, it is simple. Well, yeah, kind of... :)How it should work?For the MVP we looked for the basic functionality:A user creates a new game, and becomes an admin in that gameSharing...
2023-05-29 09:51:12
We've organized a meetup in WDev office on the topic of pakcage development in Laravel. We had great time exploring the following topics:WHAT are PHP packagesWHY should we create packages?HOW to start?Versioning packagesUsage with composerLaravel specific packagesDeveloping Laravel packagesLive coding examplesIf you are interested find the recording of the event here: Please find below some pictures taken at the event:
2023-05-15 12:06:39
I've used google analytics for couple of years and it worked quite well for me. The question arises why did I make my own analytics package. There were a couple of reasons to do so:Google analytics became quite complex and slow lately. Especially with introduction of the new Google Analytics 4 it became more complex, and I realised that I don't use even 0.1 percent of its capability. This blog and the other websites I developed as side projects only need simple things like visitor count per day in a specific period, and page views for the top visited pages. That's it!I wanted to...
2023-04-26 21:36:37
I am a big fan of Test Driven Development and trying to promote it on every possible occassion. I am doing it because having a good test suite makes me confortable when refactoring or making changes in my code. Also it saved me a couple of times from creating a hidden bug while implementing or changing something.In this blog post I'll guide you through the process how to start with TDD in any PHP project, how to install phpunit, and even how to make it fun. But let's start with a short introduction about the test driven development.TLDR;If you...
2022-11-23 20:00:00
Since Laravel 8 we can use the new and reworked model factories. They allow us to create multiple interconnected model instances using a simple and easy to read syntax. As usual Laravel has a great documentation about how to create and write these factories. In this article I don’t describe the usage of the factories, if you are interested in that check out the documentation. Instead we will go a little deeper and understand how the states work in factories. Also we will show an interesting example we run into lately, where the states worked differently as we expected.What...
2021-11-06 13:46:04
Chai is a TDD and BDD library, and comes with several flavors for assertions: should, expect and assert. In the following lessons we will take a look at both styles and see how to use them in practice.Installation and first exampleFirst we need to install chai using a package manager, for example npm:npm install chaiWhen it is done, let’s take a look at our first example with chai.See the Pen Testing with Mocha – Example 5.1 by Daniel Werner (@daniel-werner-the-decoder) on CodePen.As we see in this example we are using expect instead of assert, let’s see...
2021-04-22 08:56:50
In this post we will take a look how can we expect that an error is thrown and how to make sure no error is thrown when when everything should be fine.Asserting an error is thrownLet’s take a look on how to make sure the expected error is thrown in case when we need it. As an example lets extend our generic collection class, and create a specific collection which can store only numeric values.See the Pen Testing with Mocha – Example 4.1 by Daniel Werner (@daniel-werner-the-decoder) on CodePen.As we can see in the example above,...
2021-04-20 08:46:20
In JavaScript we often write asynchronous code, for example ajax calls, database operations etc. When testing our code we want to be able to test this asynchronous parts of our code as well. Let’s see how we can achieve this when testing with Mocha.Asynchronous code with callbacksFor testing async code which uses callbacks we can use Mocha’s done function. When passing done in the test Mocha knows that it should wait for that callback to be called. Let’s see and example. Let’s add a save method to our collection, which will operate asynchronously.See the Pen Testing with Mocha – Example 3.1...
2021-04-14 08:23:02
In the previous lesson we’ve created our first test, but used only one assertion to check if the result equals to a predefined value. Let’s take a look at the capabilities of the Chai’s assert library, and explore them through some more advanced examples.Using strictEqual and notStrictEqualIn the first example we’ve already used the equal assertion. The basic difference between equal and strictEqual is that the latter compares the types as well. The strictEqual only accept the value if it’s type and value is the same as the expected one.Let’s see and example of how to use...
2021-04-13 17:00:43
IntroductionMocha can be run both from the command line or from the browser. If you want to run it from the terminal you can use npm or yarn to install it. You can install mocha globally and use it in all your projects or install as as dev dependency in the project locally. I’d recommend installing it locally because this way you can have different versions of Mocha in different projects, and also it makes it easier to install Mocha in continuous integration system to automate the test suite.Installing MochaInstalling via command lineLet’s see how...
2021-04-12 10:25:36
Continuing the under the hood series, this time about database transactions in Laravel. I won’t repeat all the things on how you can use the transactions in Laravel. If you are not familiar with the topic you can find everything in the documentation here. We’re now focusing on how these implementations work in the background, what caused us some headache lately and how to avoid it. So let’s dive in.Transactions with closureAs you are probably already familiar with it, you can use closures in the DB facade’s transaction method, like this:DB::transaction(function () { DB::update('update users set votes...
2021-02-01 18:00:00
Just like the unit or integration tests in development, the backups may seem like unnecessary wasting time, money and effort… until a certain point. With tests this point usually comes when we do a “quick fix” on Friday afternoon, deploy it to production and realize that we unintentionally broke the whole system. The following weekend is not going to be nice for the dev team.The situation with the lack of backup is even worse. Someone hacks into your system. The database server crashes. A developer runs an update script on production but forgets the where clause. These things happen...
2020-10-25 20:01:44
When it is necessary to authenticate and authorize the access of static files, such as downloadable content, images etc, the common approach is to read the file with PHP and return the content. Laravel’s download method also works this way. There is nothing wrong with this approach. However it could lead to some performance issues if there is a high load on the server, or when serving big files.Using Nginx http_auth_request_moduleIf you use Nginx built with the http_auth_request_module you can utilize the auth_request directive to create authentication based on subrequest result.As the official documentation says:To perform...
2020-07-26 21:29:00