Getting Started with Laravel Nova

What an exciting day in Laravel history! Today, the latest addition to the Laravel ecosystem has arrived: Nova. So, what exactly is it? Well, straight from the marketing website it’s defined as, «a beautifully designed administration panel for Laravel. Carefully crafted by the creators of Laravel to make you the most productive developer in the galaxy.» In my eyes, it can be everything from an admin panel to a CMS to a CRM, and I’m Read more

Searching for HTML in an easy way

You certainly already had to grab some HTML and fetch some content inside it with PHP. Whenever you need to do this, the most common solution is to use regex and functions like strpos. Some developers try to keep code clean using classes like DomDocument, But end up having to go back to regular expressions because of poorly formed HTML. Others try to venture into the world of XPath, but end up facing the same Read more

How to specify a different .env file for phpunit in Laravel 5

Copy your .env to .env.testing, then edit the .env.testing file and change the APP_ENV parameter to make it like this APP_ENV=testing this way you will be able to specify your settings int this new file In case you don’t want to create a new .env.testing file you have to specify your variables in the phpunit.xml in the php section with the values you need, something like this <php> <env name="APP_ENV" value="testing"/> <env name="CACHE_DRIVER" value="array"/> <env Read more

Dynamic dependency injection for interface, based on user input

Finally after some days researching and thinking alot about the best approach for this, using Laravel I finally solved. I have to say that this was specially difficult in Laravel 5.2, because in this version the Session middleware only is executed in the controllers used in a route, it means that if for some reason I used a controller (not linked for a rote) and try to get access to the session it is not Read more

Microsoft WSL CentOS / Red Hat Enterprise Linux

Some distros are available only via GitHub releases. They were implemented using (a very thin C99) OS-agnostic wrapper called WSLDL. ATM, we have Alpine, Arch, Artix, CentOS, Void (glibc & musllibc) available: https://github.com/yuk7/wsldl#install-with-prebuilt-rootfs. Navigate to one of those repos, fetch latest release build (zip) e.g. CentOS-7.5.1804.zip at https://github.com/fbigun/WSL-Distro-Rootfs/releases/tag/v0.0.1. After that extract the zip, execute CentOS.exe. That will register the OS with WSL which is normally already in PATH — subsequently type centos[enter] form cmd/powershell. To Read more

What’s the point of input type in GraphQL

The Object type defined above is inappropriate for re‐use here, because Objects can contain fields that express circular references or references to interfaces and unions, neither of which is appropriate for use as an input argument. For this reason, input objects have a separate type in the system. Since posting it, I found that circular references actually are acceptable, so long as those are nilable (or else it would declare an infinite chain). But, still Read more

Docker and IPtables

TL;DR; By default, docker daemon appends iptables rules for forwarding. For this, it uses a filter chain named DOCKER. Chain FORWARD (policy DROP) target prot opt source destination DOCKER all -- 0.0.0.0/0 0.0.0.0/0 ... Chain DOCKER (1 references) target prot opt source destination Moreover, when you tell docker to expose a port of a container, it exposes it to the entire world, breaking your possibly existing iptables rules. So.. if you are running docker on Read more

Laravel custom model casts

So I ended up going down the Traits route to override various Model methods, this turns out not to be for the fainthearted as attribute casting is quite deeply embedded into the way models work. To make this work for the most general case, i.e. being able to easily add custom casts, would require a fairly major rewrite of Model. Here is the Trait I wrote to add a time cast: <?php namespace App\Models; use Read more

How to convert string to boolean php

Depending on your needs, you should consider using filter_var() with the FILTER_VALIDATE_BOOLEAN flag. filter_var( 'true', FILTER_VALIDATE_BOOLEAN); // true filter_var( 1, FILTER_VALIDATE_BOOLEAN); // true filter_var( '1', FILTER_VALIDATE_BOOLEAN); // true filter_var( 'on', FILTER_VALIDATE_BOOLEAN); // true filter_var( 'yes', FILTER_VALIDATE_BOOLEAN); // true filter_var( 'false', FILTER_VALIDATE_BOOLEAN); // false filter_var( 0, FILTER_VALIDATE_BOOLEAN); // false filter_var( '0', FILTER_VALIDATE_BOOLEAN); // false filter_var( 'off', FILTER_VALIDATE_BOOLEAN); // false filter_var( 'no', FILTER_VALIDATE_BOOLEAN); // false filter_var('asdfasdf', FILTER_VALIDATE_BOOLEAN); // false filter_var( '', FILTER_VALIDATE_BOOLEAN); // false filter_var( null, FILTER_VALIDATE_BOOLEAN); Read more


Любишь мемасики?

Подпишись на мой телеграм-канал!

Открыть
Закрыть