Category: Laravel

  • Automated Deployment of Laravel Project

    In this article I would like to share my approach to automated deployment of a Laravel project. I have been successfully using this approach for my side projects. In this article I will share Laravel project deployment on Linux (Digital Ocean) server. In a nutshell deploying Laravel project consists of “building” it (installing composer dependencies,…

  • Adding Email Headers in Laravel Application

    Adding email headers in Laravel application is quite simple. SwiftMessage can be customized using withSwiftMessage method of Mailable base class: https://laravel.com/docs/8.x/mail#customizing-the-swiftmailer-message However you have to remember to do it every time you create a new “mailable” class. Some mail APIs require you to put a special header each time you send an email. In this…

  • API Server Logging with Laravel

    When you work with APIs it is usually a good idea to log requests and responses. I already covered how to do logging when you are consuming an API. You can read about it in this post. Here we will cover how to do it when building an API service with Laravel. For example, you…

  • Exporting Records with Timezone Adjustments

    As a rule, dates in a database are stored in UTC. So, when you export records from database constrained by dates, it is a good idea to use appropriate timezone in export query. You can do it in one of two ways. One way is create incoming dates in user’s timezone, then covert time to…

  • Stream Files From S3

    When using S3 as our external storage, sometimes we have to let users download files from S3. If file is too large, it may not fit in the memory. The solution is to stream file into user’s browser straight from S3. Let’s take a look how to do it with Laravel’s Filesystem. There are 2…

  • WebSocket is closed before the connection is established

    I have been using great package by Beyondcode laravel-websockets. Recently I tried to connect to the websocket server in a new application and got the following error “failed: WebSocket is closed before the connection is established”. Strangely enough this error was manifested in Chrome and not in Firefox. After digging a little bit I found…

  • Testing API Clients

    Since an API client is a boundary between your code and the outside world you should write as little code as possible to implement it. The client should strictly do its job by sending a request and returning a response. That is why we don’t really test the clients themselves but rather the code that…

  • Laravel WebSockets as a Service

    Recently Beyondcode came out with a web sockets package for Laravel.  For my mailroom project I decided to add push notifications when a service receives a webhook.  This a great use case for Laravel WebSockets package.  In this article we will take a look at how to install it as a service using Docker and use…

  • Testing with Service Container

    The backbone of Laravel is service container.  Service container is used for resolving classes and dependency injection.  Container comes as a standalone package, so you don’t have to have Laravel installed to use it.  Service container can be very handy when testing.  Let’s look at how we can use it . Our basic set up…

  • Custom Mail Driver for Laravel

    Custom Mail Driver for Laravel

    Out of the box Laravel supports many mail drivers, such as smtp, sendmail, mailgun, log, array, etc. But what if you wold like to use a mail service that Laravel does not have a driver for, such as Mailjet?  You can create a custom driver for that service.  This article will describe how to create…