Posts tagged #laravel

Laravel Blade Internals (Video Series)

by Liam Hammett · 1 minute read · #php #laravel

In this short video series, I take you through Laravel Blade and some things I’ve picked up from using it extensively for a long time.

We’ll see how to make Blade work from plain PHP, the additional things it does under-the-hood, how to disable the view cache, extend Blade and write your own custom directives that work reliably and effectively. Come along for the ride and watch the series.

Read more…

Laravel TALL Stack Preset

by Liam Hammett · 3 minute read · #laravel #tailwind #alpinejs #livewire

Do you enjoy using TailwindCSS, AlpineJS, Laravel and Livewire together?

Well you’re in luck! Along with Dan Harrin and Ryan Chandler, we’ve just released a preset that can provide all of this out-of-the-box with sensible defaults to get you up and running with these technologies in a flash.

Read more…

Laravel Testing - CSS Selector Assertion Macros

by Liam Hammett · 7 minute read · #laravel #testing

Laravel offers some very useful ways to test that your pages are being rendered with the right content by making assertions directly on the response object.

It’s such an elegant and fast way to be sure your application is doing what you want, but doesn’t necessarily always do what you might want.

A test doing this in Laravel may look like the following, creating an article then making sure the title of that article shows on the listing page:

Read more…

Laravel Mixins

by Liam Hammett · 4 minute read · #laravel

Have you ever wished that a PHP class had another method on it that you’d like to use? Laravel makes this dream come true through its concept of “Macroable” classes.

Macroable itself is the name of a trait Laravel comes with that is applied to many of the framework’s own classes.

This trait allows you to call a static “macro” method at runtime to add a new method to the class by executing a closure. Behind the scenes, it will use the magic __call() and __callStatic() methods PHP provides to make the method work as if it were really on the class.

Read more…

Black Friday & Cyber Monday 2019 Deals for PHP & Laravel Developers

by Liam Hammett · 4 minute read · #laravel

Black Friday and Cyber Monday deals have already started for 2019, and if you’re a PHP or specifically Laravel developer, there’s a lot to look forward to, especially if you’re looking to expand your knowledge and pick up some new skills on the cheap.

In this page I’ll be keeping you up-to-date with the best and latest deals to keep an eye on - it’s the only time of year with these kinds of huge price drops, so don’t miss out.

If you want to see the kind of deals that were up for grabs last year and what you can expect to come over the next few days, check out last year’s post.

Read more…

Run and stop multiple long-running commands from Bash with a trap

by Liam Hammett · 7 minute read · #bash #laravel #cli

Sometimes when working on a project, I’ll always want to run a handful of commands at the same time, some of which may return when they’re done, others might be long-running, like watchers or services actively exposing ports.

This is something that might seem simple to do with a basic Bash script at first, but what if your script has multiple processes running side-by-side and you want to be able to stop them all at once too?

Here we’re going to take a look at how we can achieve this with Bash traps and the single-ampersand operator.

Read more…

Laravel Blade Helpers

by Liam Hammett · 3 minute read · #open-source #laravel

Laravel’s Blade templating engine offers a ton of convenient directives you can use to make your view files beautiful and abstract anything that may be too complex or verbose to live inside HTML. It even gives a really handy way to add your own custom directives using the Blade::directive(…) method.

However, the callback in custom directives only receives a single parameter - the raw string expression from the view file. It seems to be rare that developers actually parse the contents of the expression itself within the directive, opting instead to pass the entire expression as arguments to a helper function or a method on another class. For example:

BladeHelper::directive('uppercase', function($expression) {
    return "<?php echo strtoupper($expression); ?>";
});

Read more…

Black Friday 2018 Deals for Laravel Developers

by Liam Hammett · 6 minute read · #laravel

It’s that time of the year again, and over the next few days there will be some awesome deals in all sorts of areas - retail and tech especially. As a Laravel developer, there’s a lot of goodies to get your hands on for some insanely discounted prices!

Here I’ll try to sum up some of the great deals you might want to get your hands on.

Laravel Nova - 30% off

Read more…

Throttle Simultaneous API Requests with Laravel

by Liam Hammett · 2 minute read · #open-source #php #laravel

Laravel comes with a handy ThrottleRequests middleware out-of-the-box that blocks users of an API from being able to send more than a particular amount of requests within a defined amount of time.

This is extremely useful for preventing an API from being abused by spammed requests, but isn’t suitable for every use case.

What about an API call that takes a lot of limited processing power, or performs an action that simply can’t be running twice at the same time?

Read more…

Laravel Set .env File Variable

by Liam Hammett · 2 minute read · #open-source #php #laravel