API Authentication using Laravel Sanctum

https://res.cloudinary.com/techvblogs/image/upload/v1617996645/banner/rjswos1leslvm0h4asbm.png

What is Laravel Sanctum?

Laravel Sanctum provides a featherweight authentication system for SPAs (single page applications), mobile applications, and simple, token-based APIs. Sanctum allows each user of your application to generate multiple API tokens for their account. These tokens may be granted abilities/scopes which specify which actions the tokens are allowed to perform. Here are some reasons you might want to choose Sanctum over Passport:

  1. Passport is implemented with OAuth2 authentication. If you are not using that, then Sanctum is your go-to for issuing API tokens.
  2. Sanctum is a featherweight, meaning it is light and simple to implement.
  3. Sanctum works with SPAs (Single Page Applications like Vue, Angular, and React) and supports mobile application authentication.

Getting started

First, open Terminal and run the following command to create a fresh laravel project:

composer create-project --prefer-dist laravel/laravel larasanctum-api

or, if you have installed the Laravel Installer as a global composer dependency:

laravel new larasanctum-api

Setup Database Detail

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=<DATABASE NAME>
DB_USERNAME=<DATABASE USERNAME>
DB_PASSWORD=<DATABASE PASSWORD>

Read Also: Firebase Push Notification Laravel Tutorial

Installation and Setup

Now would be a good time to start the Laravel application to make sure everything is working as expected:

cd larasanctum-api
php artisan serve

Let’s add Laravel Sanctum to it. First, we need to install Laravel Sanctum into our application using Composer:

composer require laravel/sanctum

Next, we’ll publish Laravel Sanctum configuration and migration files using the following command:

php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"

Now, run the database migrations:

php artisan migrate

To use tokens for users, add the HasApiTokens trait inside the User model.

Open the app/Models/User.php file and add the following modifications:

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasFactory, Notifiable, HasApiTokens;
}

Setup Middleware

Edit your app/Http/Kernel.php file to add Sanctum’s middleware into your API middleware group.

'api' => [
    'throttle:api',
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
    \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
],

Building the API

Let’s start with registering for an account. In your terminal create the controller responsible for authentication by running the following Artisan command:

php artisan make:controller AuthController

Now open the routes/api.php file to create the route for registering a user:

use App\Http\Controllers\AuthController;

Route::post('/register',[AuthController::class,'register']);

Open app/Http/Controllers/AuthController.php and create a method to register a user:

use Illuminate\Support\Facades\Hash;

public function register(Request $request){
    $post_data = $request->validate([
        'name'=>'required|string',
        'email'=>'required|string|email|unique:users',
        'password'=>'required|min:8'
    ]);

    $user = User::create([
        'name' => $post_data['name'],
        'email' => $post_data['email'],
        'password' => Hash::make($post_data['password']),
    ]);

    $token = $user->createToken('authToken')->plainTextToken;

    return response()->json([
        'access_token' => $token,
        'token_type' => 'Bearer',
    ]);
}

First, we validate the incoming request to make sure all required variables are present. Then we persist the supplied details into the database. Once a user has been created, we create a new personal access token for them using the createToken() method and give the token a name of authToken. Because createToken() will return an instance of Laravel\Sanctum\NewAccessToken, we call the plainTextToken property on the instance to access the plain-text value of the token. Finally, we return a JSON response containing the generated token as well as the type of the token.

Next, create a route for the login user, open routes/api.php, and update the following code into a file:

Route::post('/login', [AuthController::class, 'login']);

Now add login method to AuthController

use Illuminate\Support\Facades\Auth;

public function login(Request $request){
    if (!\Auth::attempt($request->only('email', 'password'))) {
        return response()->json([
            'message' => 'Invalid login details'
        ], 401);
    }

    $user = User::where('email', $request['email'])->firstOrFail();

    $token = $user->createToken('authToken')->plainTextToken;

    return response()->json([
            'access_token' => $token,
            'token_type' => 'Bearer',
    ]);
}

Add the routes that require authentication inside the middleware group. As the login route doesn’t use the authentication middleware, it goes outside the middle group.

routes/api.php

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\AuthController;

Route::post('/register',[AuthController::class,'register']);
Route::post('/login', [AuthController::class, 'login']);

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

Now, All sets to go, and Let’s test API routes.

Create a new User

API Authentication using Laravel SanctumLogin User

API Authentication using Laravel SanctumGet Authenticated User

API Authentication using Laravel Sanctum

Thank you for reading this article.

It’d be a good idea to follow along with the simple demo app that can be found in this GitHub repo.

Read Also: Implement Passport In Laravel

Laravel News Links

How Steel Chains are Made

https://theawesomer.com/photos/2021/04/how_steel_chain_is_made_t.jpg

How Steel Chains are Made

Link

Think of how strong a steel chain can be. Then imagine the forces that must be necessary to shape and connect its links. In this video from Engineering and Architecture, we get an up-close look at a specialized machine that takes lengths of steel wire, then scores, cuts, bends, and presses the pieces together.

The Awesomer

The 5 Best Tools to Download Streaming Video From Any Website

https://static1.makeuseofimages.com/wordpress/wp-content/uploads/2021/04/videodownloadhelper.png

Most of today’s internet traffic is spent streaming online video, with YouTube taking up a massive chunk. Over 400 hours of video content is uploaded to YouTube every minute, and YouTube has a greater reach in the 18-49 demographic than even cable TV.

And then you have to consider other video streaming sites like Vimeo, Dailymotion, Metacafe, Twitch, and so on. That’s a lot of data flowing around—and if your ISP caps your monthly data allowance, then all this video streaming can be expensive.

The solution is to capture or download online videos to watch offline, allowing you to re-watch as many times as you want without wasting data.

Here are some of the best tools for capturing and downloading streaming video from websites online so you can watch them offline.

1. Video DownloadHelper


Available on: Chrome, Firefox.

Supported sites: YouTube, Facebook, Instagram, Vimeo, Dailymotion, Lynda, Twitter, Udemy, and hundreds of other sites.

Video DownloadHelper is easily one of the most useful browser extensions for downloading streaming video that you’ll ever install. The downside (sort of) is that you have to install it on your browser; if you already run a lot of extensions, the last thing you need is another one making Chrome even slower. But if you download a lot of videos on a day-to-day basis, Video DownloadHelper is definitely worth it.

The extension adds a button next to your browser’s address bar. Whenever you come across an online video, just click the button to download any video on the current page. Use the pop-up box to decide where to save it on your computer.

2. 4K Video Downloader


Available on: Windows, Mac, Linux.

Supported sites: YouTube, Facebook, Vimeo, Flickr, Dailymotion, and several other sites.

4K Video Downloader is the simplest and most straightforward tool to capture video from a website. We recommend it if you want a no-hassle option that requires close to zero effort on your part. It works extremely quickly and doesn’t throttle your download, plus it’s really easy to get to grips with.

Just copy the URL of an online video and paste it into 4K Video Downloader. You can paste links to YouTube playlists or YouTube channels to download every video available, and you can even subscribe to YouTube channels and auto-download new videos as they’re made available. You can also download the annotations and subtitles in YouTube videos.

Video downloads are available in 8K, 4K, 1080p, or 720p (as long as the source video was uploaded at that resolution, of course). Videos can be downloaded in MP4, MKV, and FLV formats. Or you can download only the audio portion in MP3 or M4A formats.

3. Freemake Video Downloader


Available on: Windows.

Supported sites: YouTube, Facebook, Liveleak, Veoh, Vimeo, Dailymotion, and dozens of other sites.

Freemake Video Downloader is one of the most popular video downloading tools out there. It’s completely free, easy to use, and relatively flexible as far as quality and format options are concerned. The one big downside is that it’s only available on Windows.

Videos can be downloaded in a handful of formats, including AVI, FLV, MKV, MP4, and WMV. Videos can also be downloaded in MP3 format if you only want the audio portion. The actual process only requires the URL of the video—just copy and paste it in.

4. JDownloader


Available on: Windows, Mac, Linux.

Supported sites: Nearly any site with streaming video.

JDownloader is like Freemake Video Downloader but with a twist. You take the URL of any page that has a streamed video on it, paste it into the app, and it will scan the page for all the videos it can detect. You get to pick which of the detected videos you want to download.

The nice thing about JDownloader is that you don’t need the direct URL of a specific video. Take a MakeUseOf article with five embedded videos, for example, and all of them will be detected. No need to fumble around finding out the direct URL of the video. This makes it very easy to capture several videos at once.

However, be aware that the installer comes with bundleware, which is where other programs are pushed on you that you don’t need. When you run the installer, you’ll come across a page that offers to install "Bing Search" or something else. On this page, the buttons will change to Decline and Accept. Ensure you click Decline, because this will prevent bundleware from being installed on your system.

5. youtube-dl


Available on: Windows, Mac, Linux.

Supported sites: YouTube, Facebook, HBO, Metacafe, Vimeo, Dailymotion, and thousands of other sites.

youtube-dl is a tool for advanced users who are comfortable using the command line. If you prefer graphical interfaces, save yourself the headache and just use one of the ones listed above.

But if you’re okay with command line utilities, then youtube-dl offers the most flexibility of any video downloading tool. It’s complicated enough to have a non-trivial learning curve though, so prepare to read the documentation, or else you’ll be lost.

You could also try youtube-dl-gui, which is an unofficial front-end user interface that’s available for Windows and Linux.

Features include several video selection and quality parameters, playlist processing, download rate limit, batch video downloading, automatic naming of files, inclusion of ads, and downloading subtitles (for sites like YouTube).

The following formats are supported: 3GP, AAC, FLV, M4A, MP3, MP4, OGG, WAV, and WEBM.

The Last Resort for Capturing Online Videos

If you encounter a video that isn’t supported by any of the above tools, the last resort is to play the video in full screen mode and record your screen as it plays.

It’s not a perfect solution, but it normally works when nothing else does. Keep in mind, however, that some sites and apps (especially TV streaming services) will not let a screen recorder capture the footage. When you go to play the video back again, you will just be faced with a blank screen.

If you can get the direct URL of an online video, you can also use VLC to play and record online videos as a kind of streaming video recorder.

MUO – Feed

Heads-Up Comparison: P365 vs. Hellcat vs. MAX-9 vs. M&P9 Shield Plus

https://cdn0.thetruthaboutguns.com/wp-content/uploads/2021/04/Quadfecta-SIG-SAUER-P365-Springfield-Hellcat-Ruger-MAX-9-Smith-Wesson-MP9-Shield-Plus.jpg

TTAG’s Managing Editor, Dan Zimmerman, and I took all four of the hottest, most in-demand concealed carry guns on the market — the four micro-compacts with double-digit capacity, flush-fit magazines — and hit the range. Shooting the SIG SAUER P365, Springfield Hellcat, Ruger MAX-9, and Smith & Wesson M&P9 Shield Plus (listed in order of when they were released) back-to-back-to-back-to-back, the following is our takeaways on how these four fantastic little pistols stack up.

The size and weight specs more or less tell the story of how these four pistols compare on paper, though there is some nuance that can’t be seen or felt in these figures.

In the Rumble-hosted video embedded above (direct link HERE), Dan and I both put a full mag through all four of these guns and provide some thoughts and feedback. Check it out!

As an example of an on-paper stat that may be misleading in real life, while the Hellcat is shorter in max height than the P365, its backstrap is longer so its heel sticks out a little farther than the P365’s. The Hellcat’s magazine baseplate is nearly parallel with the slide, though, whereas the P365’s angles downward toward the frontstrap, so the P365’s toe sticks out more than the Hellcat’s.

For the vast majority of concealed carriers, it’s the heel of the grip that prints (“pokes” into one’s cover garment, giving away the fact that an object is underneath) first, before any other part of the gun. So, while the Hellcat is technically shorter, the P365 with its more rounded (slightly “bobbed”), shorter heel will likely conceal like the shorter gun.

On the other hand, the frontstrap is where the shooter’s fingers do most of their gripping, and the lower toe of the P365 allows my men’s size large hands to place precisely half a pinky firmly on the frontstrap. That same pinky wraps underneath the grip of the Hellcat.

Even that, however, doesn’t really translate to what you might expect when going loud with these little pistols. Thanks to the larger grip circumference and different shape of the Hellcat’s grip, it feels and shoots like it’s larger than the P365 even if one’s pinky is wrapped under the mag.

Okay, onto our thoughts of how each micro-compact concealed carry handgun stacks up compared to the others:

SIG SAUER P365

SIG’s little P365 shook up the concealed carry market when it was released in early 2018. In a sea of slim, easy-to-conceal pistols with 6+1 and 7+1 capacities, the P365’s 10+1 capacity within the same tiny footprint was a full-on mic drop that gave it an immediate, huge leg up on the competition.

Shoehorning 10+ rounds into a skinny micro-compact was and certainly still is a fantastic recipe for sales success, and, as this very article shows, others have jumped into the fray.

All that said, I’d be remiss not to mention that the SIG SAUER P365 was the first to accomplish this feat only if you don’t count the KELTEC P11, which was released in 1995 and would absolutely belong in this group were it not discontinued in 2019.

At least, on paper the P11 belongs here (5.6″ length, 4.3″ height, 1.0″ width, 17.1 oz, 10+1 flush-fit with a 12-round and 15-round magazine available). Though specific units were rock solid, as a whole the P11 wasn’t reliable enough to be taken seriously by most concealed carriers and they — we — instead chose pistols with lower capacities but higher trustworthiness.

Anyway, three years later and the P365 still feels the smallest of these four handguns. Much of that can be chalked up to it having the smallest grip circumference. Sure, it’s the lightest of the four by a small amount and perhaps it balances slightly differently, but I think these differences are too small to really notice on the range.

What you do notice is more muzzle flip than the other guns. I’ve always considered my personal EDC since 2018, my P365 seen in these photos, to be a highly controllable gun and dang do I shoot the thing quickly and accurately, but without a doubt it has the most felt recoil and muzzle flip of the guns in this quadfecta. Next is the Ruger MAX-9, which is only very slightly less “flippy” than the P365, then there’s a jump to the Springfield Hellcat, which is noticeably softer, and then another solid leap to the Smith & Wesson M&P9 Shield Plus, which shoots like a well-tuned compact, not a sub-compact or micro-compact.

SIG’s X-RAY3 sights are fantastic; exactly what I prefer. A bright, eye-catching, tritium-illuminated front sight and an all-black, serrated rear. They’re steel, durable, quick, and accurate. One could argue that the tritium-illuminated fiber optic front sight on the MAX-9 is better, but my eye prefers the P365’s front dot.

There has been some variability in P365 trigger pull quality. For instance, my early P365 here has a slightly better trigger than my P365XL, which was made two years later. In either case, though, I’d describe both triggers as very good — well above the average for compact (or sub-compact or micro-compact) polymer pistols of its time.

The P365’s trigger has a fairly short travel, followed by a skosh of creep before a crisp break. The reset travel is fairly short and the reset is nicely tactile and audible. Pull weight is exactly what I prefer in a carry gun: about 5 pounds.

Grip texture on the P365 is just about perfect for me. It’s basically “pebbled” like sandpaper, but with the peaks softened just enough that it doesn’t cause too much irritation if it’s against your skin while being carried concealed. The grip is smooth in the nicely-shaped trigger guard undercut and the underside of the beavertail, which is the correct choice in both cases, and textured elsewhere.

The large magazine release is easy to use, but not so tall that it risks accidental activation. I appreciate the windows on each side of the bottom of the grip frame, which allow a jammed magazine to be stripped out more easily.

Front and rear slide serrations are traditional and simple.

But they’re also very grippy with 90-degree edges and enough depth to provide really solid purchase. The P365 ranks second for functional slide serrations.

After shooting all four guns, I won’t be trading in my P365. Without a question I shoot the Shield Plus a little bit better — again, it shoots like a compact — but it’s just enough larger and heavier and I’ve become so familiar and used to my P365 that it’s still my choice.

Springfield Hellcat

For an MSRP premium of just $30, you’d be silly not to buy the optics-ready Hellcat. As the first challenger to the P365, though, Springfield clearly wanted to undercut the SIG’s MSRP and the non-optics-cut base model allowed ’em to do that by $10.

Springfield also [literally] one-upped the P365’s capacity by squeezing 11 rounds into the Hellcat’s magazine. This gives it the highest flush-fit capacity of all four of these little gats, despite the fact that it’s the shortest of the quadfecta. Impressive.

As mentioned above, the Hellcat shoots pretty darn softly given its lilliputian size and light weight. It’s an easy gun to shoot well. It’s an extremely easy micro-compact to shoot well.

The Hellcat’s tritium front sight with bright green outline is great — a lot like the P365’s. I’m definitely not a fan of the rounded-notch rear with white outline, though obviously this is personal preference. No argument on the quality of the steel sights.

Dan swapped an Apex trigger into this Hellcat, which improved its trigger in all ways (obviously) but it’s fair to say that the Hellcat ships from Springfield with an extremely competitive trigger pull quality to begin with. It’s better than what we all became used to with polymer pistols of the past. It still isn’t the best trigger of this group, though.

While the grip texture on the Hellcat is similar to that of the P365, the grip shape is not — it’s quite blocky. Sides, front, and back are fairly darn straight and flat across and the edges between all four sides are rounded, yes, but make a sharper transition than on most pistols.

I do not like the feel of the Hellcat in my hand. It’s just too square for me. It’s still small, of course, so it’ll fit basically anyone’s hand (or at least shouldn’t be too large for anyone), but I just find it weird. Too flat across the backstrap, in particular, with too-sharp transitions to the sides.

Dan has smaller hands (and less hair on his head and he’s also shorter and, like, super old and stuff), though, and feels differently. He likes the size and shape of the Hellcat’s grip frame. I think the joints in his fingers and the shape of his palm and thumb joint and such align better with the edges of the grip.

One thing we certainly agree on is that the Hellcat’s slide serrations suck. They look good, but they’re so dang shallow they’re barely functional. Even with dry hands I worry about sliding off of the serrations while trying to manipulate the slide.

If this were my carry gun I’d put sandpaper style grip tape in-between, below, and behind the serrations (probably cutting my own from Talon Grips granulate material). Alternatively, it would be a further selling point to running a micro red dot and I’d karate chop that bad boy as my sole means of slide manipulation.

Dan has put a ton of rounds through this Hellcat and it has proven itself reliable and easy to carry. It’s a good shooting gun, too. Without a doubt, it’s a very good choice for concealed carry.

Ruger MAX-9

There’s no question whatsoever that Ruger’s new MAX-9 represents the best value of the pack. At an MSRP of just $499 (and when the market gets back to normal it’s going to retail for substantially less than the other three pistols) it includes the optics-ready slide and the tritium-illuminated fiber optic front sight. Heck of a deal.

The MAX-9 isn’t as flippy as my P365, but it has some snap to it. It’s the skinniest gun of the group with the second smallest grip circumference, but it’s taller than the SIG and Springfield, which pair very closely on height and then the Ruger and S&W pair closely at about a third of an inch taller.

Trigger pull on the MAX-9 feels far lighter than its approximately five-and-a-half-pound break weight. This is likely due to Ruger’s rotary sear, which gives the trigger a smooth, rolling break that lacks the more typical feel of take-up followed by a firm “wall.”

When the trigger does break it’s clean and crisp. If you ride the reset it’s a little shorter than the initial pull, but I did find the reset to be a bit on the light side in terms of its sound and feel. Overall this is a very good trigger, and doubly so for anyone who prefers a rolling style break.

Sights are great and allowed us to shoot rapidly and accurately. While the front is undeniably easy and fast to pick up, it just doesn’t snag my eye as well as the front sight on the P365 and Hellcat.

While it looks fairly square and blocky — and it is compared to the P365 or Shield Plus — the slimmer width and more rounded edges feel more comfortable and less blocky than the Hellcat. It’s also shorter front-to-rear, so it feels smaller in the hand than all but the P365.

Grip texture on the MAX-9 is the most love handle-friendly. Though very similar in appearance to the SIG’s and Springfield’s texture, the Ruger’s is smoothed out even more — flatter high points — and is therefore less aggressive, less grippy, and more comfortable. At least on the sides.

On the frontstrap and backstrap it has more bite than on the sides, which is how it should be. Frankly, if I made a pistol like this (and didn’t care about lefties) I’d design the left side of the grip to be extra comfortable and the back, front, and right side to be extra grippy.

Of the four guns in our quadfecta here, the MAX-9’s magazine release is the most shrouded and flush and, therefore, takes the most deliberate action to activate. The same goes for the MAX-9’s slide catch, which is gated by a polymer ridge that makes it difficult to engage manually. Overall its controls, including its takedown method, are the most difficult to use of the four guns.

That said, the manual safety on the Ruger MAX-9 is just right. It’s small yet easy to reach and use, with positive detent clicks in both positions. While all four pistols do offer a manual thumb safety as an option, the MAX-9 was the only gun in our test that was so equipped so we can’t compare this feature.

Ruger wins the slide serration contest. While relatively traditional like those on the P365, the MAX-9 provides more empty space between thinner ridges and it’s really grippy.

Perhaps that change in angle also helps, but whatever the secret is the end result is extremely effective slide serrations that you won’t slip off of. If the judges give the MAX-9’s slide serrations a 10, the P365 gets an 8, the Shield Plus a 4, and the Hellcat a DNF.

The Ruger MAX-9 is a good gun that, for whatever reason, doesn’t feel quite as nice or as refined as the others and is a little taller than the P365 and Hellcat, but shoots accurately and reliably and represents one hell of a good value.

Smith & Wesson M&P9 Shield Plus

Still a micro-compact, the Shield Plus represents a meaningful bump in backstrap length versus the P365 despite its identical 10+1 flush-fit capacity. It’s also the widest gun here.

While S&W officially states the Shield Plus’ width, exclusive of the controls, as 0.94 inches I must disagree. The widest part of the palm swell measures 1.06 inches in my calipers (and it does measure out at S&W’s stated 1.1 inches from the slide stop to the other side of the slide).

Front-to-rear length of the grip frame is also significantly longer than any of the other guns here. And the Shield Plus weighs two ounces more.

Still, it’s a half inch shorter and about 0.2 inches skinnier than most of the smaller sub-compacts out there, so I think it’s fair to say it still clearly belongs right here in the micro-compact category.

On the plus side, this small amount of additional size packs a large amount of prowess on the range. The Shield Plus is markedly flatter and softer shooting than the other three pistols in this roundup, and the larger grip circumference and curvier shape provide tons of confidence and control.

As mentioned previously, the Shield Plus shoots like a well-sorted sub-compact or maybe even compact pistol. I’d put it head-to-head with a GLOCK 19, for instance, and I expect most shooters would outperform on speed and accuracy with the Shield Plus.

Additionally, this bad boy has the best trigger of the bunch. Yes, it’s better than the aftermarket trigger in the Hellcat. Holy heck is it short and crisp with an insanely short, crisp reset as well. It feels like a competition trigger.

In fact, perhaps it’s too good? Trigger pull weight is right at three pounds. It’s awesome on the range, but it’s pretty dang light for concealed carry self-defense use. Following all safety best practices related to holster choice, holstering, and use it obviously won’t present any sort of issue, but it’s undoubtedly a deviation from the norm for a self-defense gun without a manual safety (though a thumb safety is an option).

On the base model, which is what Dan and I tested, the Shield Plus’ standard 3-dot sights are nothing to write home about. It’s your typical, white painted dot front and 2-dot rear. No tritium or other flavor of night visibility.

Night sights are an option, of course, but they raise the MSRP to $623 ($44 higher than the closest competitor) while the SIG, Springfield, and Ruger all sport tritium as standard.

Grip texture on the Shield Plus is just about dead-on perfect. It provides more grip and control than appearances might suggest, yet it won’t scratch up or overly irritate the tender princess skin on your hip. It’s the sharpest and most aggressive of these four pistols, though.

The tapered shape of the Shield Plus’ grip as it transitions from rounded palm swells down to a somewhat sharply rounded or tapered backstrap sets it apart in this group. As blocky as the Hellcat is, the Shield Plus’ grip might stand out even more in the other direction.

I’m a big fan of the texture, size, and shape of this grip frame and I found that the rounded/tapered backstrap gave me a really clear index point or frame of reference for where the muzzle was pointing. Sort of an intuitive feel for the exact orientation of the gun.

The backstrap, as sharply rounded as it is, isn’t as comfortable as the backstrap of the P365 as it focuses its force in a more distinct vertical line across my palm, but I love how functional it is. It gives me confidence and I really feel like I can “drive” the Shield Plus hard, with great control and intuitive knowledge of where the gun is pointing.

Dan, however, prefers the wider, flatter backstrap feel of the other pistols in our heads-up round-up quadfecta shootout. Bottom line: a lot of this stuff boils down to personal preference.

That said, there’s zero question whatsoever that the Shield Plus is the best shooting pistol here — in part, yes, because it’s the largest and heaviest — and that it has the best trigger.

What it doesn’t have, though, is the best slide serrations even if they might look the niftiest.

I’ve never thought of the M&P’s serrations as sub-par or anything, and they’re without a doubt plenty functional and nothing I would normally complain about, but in this heads-up comparison they simply don’t compete on the same level as the P365’s and MAX-9’s.

Granted, slide serrations aren’t an end-all-be-all feature and I wouldn’t necessarily discount carrying a gun due to mediocre slide serrations (though the Hellcat truly has a problem in this regard and needs an overhaul to achieve slide serration mediocrity). Again though, it was one clear area in which these four pistols differed so I chose to call it out.

Ultimately, I came close. Close to putting the Shield Plus on my hip in place of my P365. I simply love how the Shield Plus shoots.

It ended up being the extra size — namely the well over a half-inch more backstrap height and how the heel of the grip juts out much farther and to a sharper point — that kept the SIG in my holster. Frankly, it’s hollow, unused polymer in the heel of the Shield Plus and I think they should have bobtailed the thing hard.

We’re living in a golden age of concealed carry pistols, that much is for sure. In this heads-up comparison there really isn’t a loser. Every single one of these pistols is reliable, accurate, and easy to conceal. They all have great triggers, great sights (or at least the option of great sights), optics cuts (or the option for that), and double-digit capacities.

It’s remarkable, really, to pack so much into such small pistols. For me, I’m sticking with the “original” — I like the P365 the best. Dan prefers the Hellcat. In a competition stage we’d both shoot the Shield Plus. The MAX-9 knocks it out of the park on performance per dollar.

They’re all great guns.

 

The Truth About Guns

Heads-Up Comparison: P365 vs. Hellcat vs. MAX-9 vs. M&P9 Shield Plus

https://cdn0.thetruthaboutguns.com/wp-content/uploads/2021/04/Quadfecta-SIG-SAUER-P365-Springfield-Hellcat-Ruger-MAX-9-Smith-Wesson-MP9-Shield-Plus.jpg

TTAG’s Managing Editor, Dan Zimmerman, and I took all four of the hottest, most in-demand concealed carry guns on the market — the four micro-compacts with double-digit capacity, flush-fit magazines — and hit the range. Shooting the SIG SAUER P365, Springfield Hellcat, Ruger MAX-9, and Smith & Wesson M&P9 Shield Plus (listed in order of when they were released) back-to-back-to-back-to-back, the following is our takeaways on how these four fantastic little pistols stack up.

The size and weight specs more or less tell the story of how these four pistols compare on paper, though there is some nuance that can’t be seen or felt in these figures.

In the Rumble-hosted video embedded above (direct link HERE), Dan and I both put a full mag through all four of these guns and provide some thoughts and feedback. Check it out!

As an example of an on-paper stat that may be misleading in real life, while the Hellcat is shorter in max height than the P365, its backstrap is longer so its heel sticks out a little farther than the P365’s. The Hellcat’s magazine baseplate is nearly parallel with the slide, though, whereas the P365’s angles downward toward the frontstrap, so the P365’s toe sticks out more than the Hellcat’s.

For the vast majority of concealed carriers, it’s the heel of the grip that prints (“pokes” into one’s cover garment, giving away the fact that an object is underneath) first, before any other part of the gun. So, while the Hellcat is technically shorter, the P365 with its more rounded (slightly “bobbed”), shorter heel will likely conceal like the shorter gun.

On the other hand, the frontstrap is where the shooter’s fingers do most of their gripping, and the lower toe of the P365 allows my men’s size large hands to place precisely half a pinky firmly on the frontstrap. That same pinky wraps underneath the grip of the Hellcat.

Even that, however, doesn’t really translate to what you might expect when going loud with these little pistols. Thanks to the larger grip circumference and different shape of the Hellcat’s grip, it feels and shoots like it’s larger than the P365 even if one’s pinky is wrapped under the mag.

Okay, onto our thoughts of how each micro-compact concealed carry handgun stacks up compared to the others:

SIG SAUER P365

SIG’s little P365 shook up the concealed carry market when it was released in early 2018. In a sea of slim, easy-to-conceal pistols with 6+1 and 7+1 capacities, the P365’s 10+1 capacity within the same tiny footprint was a full-on mic drop that gave it an immediate, huge leg up on the competition.

Shoehorning 10+ rounds into a skinny micro-compact was and certainly still is a fantastic recipe for sales success, and, as this very article shows, others have jumped into the fray.

All that said, I’d be remiss not to mention that the SIG SAUER P365 was the first to accomplish this feat only if you don’t count the KELTEC P11, which was released in 1995 and would absolutely belong in this group were it not discontinued in 2019.

At least, on paper the P11 belongs here (5.6″ length, 4.3″ height, 1.0″ width, 17.1 oz, 10+1 flush-fit with a 12-round and 15-round magazine available). Though specific units were rock solid, as a whole the P11 wasn’t reliable enough to be taken seriously by most concealed carriers and they — we — instead chose pistols with lower capacities but higher trustworthiness.

Anyway, three years later and the P365 still feels the smallest of these four handguns. Much of that can be chalked up to it having the smallest grip circumference. Sure, it’s the lightest of the four by a small amount and perhaps it balances slightly differently, but I think these differences are too small to really notice on the range.

What you do notice is more muzzle flip than the other guns. I’ve always considered my personal EDC since 2018, my P365 seen in these photos, to be a highly controllable gun and dang do I shoot the thing quickly and accurately, but without a doubt it has the most felt recoil and muzzle flip of the guns in this quadfecta. Next is the Ruger MAX-9, which is only very slightly less “flippy” than the P365, then there’s a jump to the Springfield Hellcat, which is noticeably softer, and then another solid leap to the Smith & Wesson M&P9 Shield Plus, which shoots like a well-tuned compact, not a sub-compact or micro-compact.

SIG’s X-RAY3 sights are fantastic; exactly what I prefer. A bright, eye-catching, tritium-illuminated front sight and an all-black, serrated rear. They’re steel, durable, quick, and accurate. One could argue that the tritium-illuminated fiber optic front sight on the MAX-9 is better, but my eye prefers the P365’s front dot.

There has been some variability in P365 trigger pull quality. For instance, my early P365 here has a slightly better trigger than my P365XL, which was made two years later. In either case, though, I’d describe both triggers as very good — well above the average for compact (or sub-compact or micro-compact) polymer pistols of its time.

The P365’s trigger has a fairly short travel, followed by a skosh of creep before a crisp break. The reset travel is fairly short and the reset is nicely tactile and audible. Pull weight is exactly what I prefer in a carry gun: about 5 pounds.

Grip texture on the P365 is just about perfect for me. It’s basically “pebbled” like sandpaper, but with the peaks softened just enough that it doesn’t cause too much irritation if it’s against your skin while being carried concealed. The grip is smooth in the nicely-shaped trigger guard undercut and the underside of the beavertail, which is the correct choice in both cases, and textured elsewhere.

The large magazine release is easy to use, but not so tall that it risks accidental activation. I appreciate the windows on each side of the bottom of the grip frame, which allow a jammed magazine to be stripped out more easily.

Front and rear slide serrations are traditional and simple.

But they’re also very grippy with 90-degree edges and enough depth to provide really solid purchase. The P365 ranks second for functional slide serrations.

After shooting all four guns, I won’t be trading in my P365. Without a question I shoot the Shield Plus a little bit better — again, it shoots like a compact — but it’s just enough larger and heavier and I’ve become so familiar and used to my P365 that it’s still my choice.

Springfield Hellcat

For an MSRP premium of just $30, you’d be silly not to buy the optics-ready Hellcat. As the first challenger to the P365, though, Springfield clearly wanted to undercut the SIG’s MSRP and the non-optics-cut base model allowed ’em to do that by $10.

Springfield also [literally] one-upped the P365’s capacity by squeezing 11 rounds into the Hellcat’s magazine. This gives it the highest flush-fit capacity of all four of these little gats, despite the fact that it’s the shortest of the quadfecta. Impressive.

As mentioned above, the Hellcat shoots pretty darn softly given its lilliputian size and light weight. It’s an easy gun to shoot well. It’s an extremely easy micro-compact to shoot well.

The Hellcat’s tritium front sight with bright green outline is great — a lot like the P365’s. I’m definitely not a fan of the rounded-notch rear with white outline, though obviously this is personal preference. No argument on the quality of the steel sights.

Dan swapped an Apex trigger into this Hellcat, which improved its trigger in all ways (obviously) but it’s fair to say that the Hellcat ships from Springfield with an extremely competitive trigger pull quality to begin with. It’s better than what we all became used to with polymer pistols of the past. It still isn’t the best trigger of this group, though.

While the grip texture on the Hellcat is similar to that of the P365, the grip shape is not — it’s quite blocky. Sides, front, and back are fairly darn straight and flat across and the edges between all four sides are rounded, yes, but make a sharper transition than on most pistols.

I do not like the feel of the Hellcat in my hand. It’s just too square for me. It’s still small, of course, so it’ll fit basically anyone’s hand (or at least shouldn’t be too large for anyone), but I just find it weird. Too flat across the backstrap, in particular, with too-sharp transitions to the sides.

Dan has smaller hands (and less hair on his head and he’s also shorter and, like, super old and stuff), though, and feels differently. He likes the size and shape of the Hellcat’s grip frame. I think the joints in his fingers and the shape of his palm and thumb joint and such align better with the edges of the grip.

One thing we certainly agree on is that the Hellcat’s slide serrations suck. They look good, but they’re so dang shallow they’re barely functional. Even with dry hands I worry about sliding off of the serrations while trying to manipulate the slide.

If this were my carry gun I’d put sandpaper style grip tape in-between, below, and behind the serrations (probably cutting my own from Talon Grips granulate material). Alternatively, it would be a further selling point to running a micro red dot and I’d karate chop that bad boy as my sole means of slide manipulation.

Dan has put a ton of rounds through this Hellcat and it has proven itself reliable and easy to carry. It’s a good shooting gun, too. Without a doubt, it’s a very good choice for concealed carry.

Ruger MAX-9

There’s no question whatsoever that Ruger’s new MAX-9 represents the best value of the pack. At an MSRP of just $499 (and when the market gets back to normal it’s going to retail for substantially less than the other three pistols) it includes the optics-ready slide and the tritium-illuminated fiber optic front sight. Heck of a deal.

The MAX-9 isn’t as flippy as my P365, but it has some snap to it. It’s the skinniest gun of the group with the second smallest grip circumference, but it’s taller than the SIG and Springfield, which pair very closely on height and then the Ruger and S&W pair closely at about a third of an inch taller.

Trigger pull on the MAX-9 feels far lighter than its approximately five-and-a-half-pound break weight. This is likely due to Ruger’s rotary sear, which gives the trigger a smooth, rolling break that lacks the more typical feel of take-up followed by a firm “wall.”

When the trigger does break it’s clean and crisp. If you ride the reset it’s a little shorter than the initial pull, but I did find the reset to be a bit on the light side in terms of its sound and feel. Overall this is a very good trigger, and doubly so for anyone who prefers a rolling style break.

Sights are great and allowed us to shoot rapidly and accurately. While the front is undeniably easy and fast to pick up, it just doesn’t snag my eye as well as the front sight on the P365 and Hellcat.

While it looks fairly square and blocky — and it is compared to the P365 or Shield Plus — the slimmer width and more rounded edges feel more comfortable and less blocky than the Hellcat. It’s also shorter front-to-rear, so it feels smaller in the hand than all but the P365.

Grip texture on the MAX-9 is the most love handle-friendly. Though very similar in appearance to the SIG’s and Springfield’s texture, the Ruger’s is smoothed out even more — flatter high points — and is therefore less aggressive, less grippy, and more comfortable. At least on the sides.

On the frontstrap and backstrap it has more bite than on the sides, which is how it should be. Frankly, if I made a pistol like this (and didn’t care about lefties) I’d design the left side of the grip to be extra comfortable and the back, front, and right side to be extra grippy.

Of the four guns in our quadfecta here, the MAX-9’s magazine release is the most shrouded and flush and, therefore, takes the most deliberate action to activate. The same goes for the MAX-9’s slide catch, which is gated by a polymer ridge that makes it difficult to engage manually. Overall its controls, including its takedown method, are the most difficult to use of the four guns.

That said, the manual safety on the Ruger MAX-9 is just right. It’s small yet easy to reach and use, with positive detent clicks in both positions. While all four pistols do offer a manual thumb safety as an option, the MAX-9 was the only gun in our test that was so equipped so we can’t compare this feature.

Ruger wins the slide serration contest. While relatively traditional like those on the P365, the MAX-9 provides more empty space between thinner ridges and it’s really grippy.

Perhaps that change in angle also helps, but whatever the secret is the end result is extremely effective slide serrations that you won’t slip off of. If the judges give the MAX-9’s slide serrations a 10, the P365 gets an 8, the Shield Plus a 4, and the Hellcat a DNF.

The Ruger MAX-9 is a good gun that, for whatever reason, doesn’t feel quite as nice or as refined as the others and is a little taller than the P365 and Hellcat, but shoots accurately and reliably and represents one hell of a good value.

Smith & Wesson M&P9 Shield Plus

Still a micro-compact, the Shield Plus represents a meaningful bump in backstrap length versus the P365 despite its identical 10+1 flush-fit capacity. It’s also the widest gun here.

While S&W officially states the Shield Plus’ width, exclusive of the controls, as 0.94 inches I must disagree. The widest part of the palm swell measures 1.06 inches in my calipers (and it does measure out at S&W’s stated 1.1 inches from the slide stop to the other side of the slide).

Front-to-rear length of the grip frame is also significantly longer than any of the other guns here. And the Shield Plus weighs two ounces more.

Still, it’s a half inch shorter and about 0.2 inches skinnier than most of the smaller sub-compacts out there, so I think it’s fair to say it still clearly belongs right here in the micro-compact category.

On the plus side, this small amount of additional size packs a large amount of prowess on the range. The Shield Plus is markedly flatter and softer shooting than the other three pistols in this roundup, and the larger grip circumference and curvier shape provide tons of confidence and control.

As mentioned previously, the Shield Plus shoots like a well-sorted sub-compact or maybe even compact pistol. I’d put it head-to-head with a GLOCK 19, for instance, and I expect most shooters would outperform on speed and accuracy with the Shield Plus.

Additionally, this bad boy has the best trigger of the bunch. Yes, it’s better than the aftermarket trigger in the Hellcat. Holy heck is it short and crisp with an insanely short, crisp reset as well. It feels like a competition trigger.

In fact, perhaps it’s too good? Trigger pull weight is right at three pounds. It’s awesome on the range, but it’s pretty dang light for concealed carry self-defense use. Following all safety best practices related to holster choice, holstering, and use it obviously won’t present any sort of issue, but it’s undoubtedly a deviation from the norm for a self-defense gun without a manual safety (though a thumb safety is an option).

On the base model, which is what Dan and I tested, the Shield Plus’ standard 3-dot sights are nothing to write home about. It’s your typical, white painted dot front and 2-dot rear. No tritium or other flavor of night visibility.

Night sights are an option, of course, but they raise the MSRP to $623 ($44 higher than the closest competitor) while the SIG, Springfield, and Ruger all sport tritium as standard.

Grip texture on the Shield Plus is just about dead-on perfect. It provides more grip and control than appearances might suggest, yet it won’t scratch up or overly irritate the tender princess skin on your hip. It’s the sharpest and most aggressive of these four pistols, though.

The tapered shape of the Shield Plus’ grip as it transitions from rounded palm swells down to a somewhat sharply rounded or tapered backstrap sets it apart in this group. As blocky as the Hellcat is, the Shield Plus’ grip might stand out even more in the other direction.

I’m a big fan of the texture, size, and shape of this grip frame and I found that the rounded/tapered backstrap gave me a really clear index point or frame of reference for where the muzzle was pointing. Sort of an intuitive feel for the exact orientation of the gun.

The backstrap, as sharply rounded as it is, isn’t as comfortable as the backstrap of the P365 as it focuses its force in a more distinct vertical line across my palm, but I love how functional it is. It gives me confidence and I really feel like I can “drive” the Shield Plus hard, with great control and intuitive knowledge of where the gun is pointing.

Dan, however, prefers the wider, flatter backstrap feel of the other pistols in our heads-up round-up quadfecta shootout. Bottom line: a lot of this stuff boils down to personal preference.

That said, there’s zero question whatsoever that the Shield Plus is the best shooting pistol here — in part, yes, because it’s the largest and heaviest — and that it has the best trigger.

What it doesn’t have, though, is the best slide serrations even if they might look the niftiest.

I’ve never thought of the M&P’s serrations as sub-par or anything, and they’re without a doubt plenty functional and nothing I would normally complain about, but in this heads-up comparison they simply don’t compete on the same level as the P365’s and MAX-9’s.

Granted, slide serrations aren’t an end-all-be-all feature and I wouldn’t necessarily discount carrying a gun due to mediocre slide serrations (though the Hellcat truly has a problem in this regard and needs an overhaul to achieve slide serration mediocrity). Again though, it was one clear area in which these four pistols differed so I chose to call it out.

Ultimately, I came close. Close to putting the Shield Plus on my hip in place of my P365. I simply love how the Shield Plus shoots.

It ended up being the extra size — namely the well over a half-inch more backstrap height and how the heel of the grip juts out much farther and to a sharper point — that kept the SIG in my holster. Frankly, it’s hollow, unused polymer in the heel of the Shield Plus and I think they should have bobtailed the thing hard.

We’re living in a golden age of concealed carry pistols, that much is for sure. In this heads-up comparison there really isn’t a loser. Every single one of these pistols is reliable, accurate, and easy to conceal. They all have great triggers, great sights (or at least the option of great sights), optics cuts (or the option for that), and double-digit capacities.

It’s remarkable, really, to pack so much into such small pistols. For me, I’m sticking with the “original” — I like the P365 the best. Dan prefers the Hellcat. In a competition stage we’d both shoot the Shield Plus. The MAX-9 knocks it out of the park on performance per dollar.

They’re all great guns.

 

The Truth About Guns

How to Spot a Good Bagel Recipe

https://i.kinja-img.com/gawker-media/image/upload/s–t3h9PCiw–/c_fit,fl_progressive,q_80,w_636/ds3a2ipkcgtzjccwkp3z.jpg

Of all the bakery-style bread products you can make at home, bagels might be the most intimidating. They really shouldn’t be. The dough is easy to handle and very hard to mess up; with the right recipe, even your first attempt will taste 10 times better than anything you can get outside of a legit bagel shop.

The hard part is finding that recipe. I’m here to help. I used to make bagels professionally from a recipe I developed and, nearly a decade later, it’s still what I use at home. (I haven’t published it. Yet.) But you don’t need to be a former pro to sling great bagels in your very own kitchen—you just need to know what works and what doesn’t. Here are my best tips for determining whether a recipe is worth your time.

Start with the ingredients list

On top of the obvious (bread flour, water, salt, yeast), you’ll want a recipe that calls for a thick liquid sweetener. Traditionally, New York-style bagels use barley malt syrup and Montreal-style bagels use honey. I’ve used both, and prefer molasses because it’s cheap, common, and works great.

Next, work out the hydration percentage. It should be about 50%, which is much lower than other types of bread. This produces a dense, sturdy dough that holds up to boiling water and gets super chewy in the oven. Slightly higher hydration is fine, but once you hit 60% it turns into pizza dough.

Next, look at the directions

This is where things tend to get hairy. Bagels aren’t technically difficult to make, but doing it right takes time. Lots of recipes try to get around the time commitment by taking shortcuts that always hurt the finished product. Treat them like the red flags they are—if you see one, move along:

  • No refrigeration: If a recipe doesn’t have you refrigerate the formed bagels overnight, it’s trash. A long, slow rise at a low temperature fully develops the gluten, locks the shape in place, adds some funky tang, and produces those iconic fermentation blisters on the crust. I can’t overstate the importance of this step.
  • Baking soda in the water bath: Baking soda is a weak substitute for lye, which is for pretzels. Bagels are famously not pretzels; they get their shiny, snappy crust from slow fermentation, boiling water, and a screaming hot oven—not lye, let alone baking soda.
  • Too much boiling: The longer you boil a bagel, the thicker and, well, crustier the crust gets. I’ve seen recipes call for 2 minutes per side, which causes me physical and emotional distress. Do you want sad, flat, rock-hard pucks? Didn’t think so. A quick dunk—20 to 30 seconds total—is plenty.

G/O Media may get a commission

Taking all of these criteria into consideration eliminates the vast majority of bagel recipes out there, but I can enthusiastically vouch for Becky Krystal and Alex Baldinger’s recipe in The Washington Post. (If you cut the boiling time in half, Peter Reinhart’s recipe is also good.) They take the time to do things right, and it shows: These recipes are easy to follow and always produce great results.

 

 

Lifehacker

6 Common Tools That Startups Use

https://static1.makeuseofimages.com/wordpress/wp-content/uploads/2021/03/Slack-Header.jpg

Are you really a startup if you don’t use Slack? It’s a question that’s been asked before. Startups, specifically tech startups as that’s what this article is about, often use particular software and tools to make life easier for the team and day-to-day running of the business.

If you are a startup that’s looking to improve its work efficiency, consider using one or more of the tools listed below.

Commonly Used Startup Tools

There is an abundance of software and tools on the market for startups to use. There’s no way we’re going to be able to look at them all in any kind of article. So, to consider some software as examples, these are some of the tools that are most commonly used.

1. Slack


Slack is one of the most common tools in the tech world. Everybody uses Slack from startups to YouTube teams.

The tool is for communication within your organization. Slack works as a channel-based messaging platform for organizations to use in order to improve communications. You can direct message other team members, and send messages to larger groups.

Related: What Is Slack and How Does It Work?

The tool is perfect for making it easy to talk to teams and staff instantly, without the need for emails. Slack also supports the integration of other software and tools so that you can have all of your workplace tools in one space.

For example, you can integrate your calendar so you can send reminders in messages about upcoming events or meetings. You can even integrate services like Google Drive to create Google Docs without leaving your Slack workspace.

2. Asana


Asana is a team and task management tool. Using the platform, you put tasks on To-Do lists for different teams. From here, you can assign tasks to certain team members, and set deadlines as well.

The tool makes it much easier for teams and management to keep on top of projects and tasks so that there’s less need for catch-ups. Reporting tools on Asana make it easy to see exactly what your teams have been getting up to, as well as the to-do list style making it easy for team members to keep track of their tasks.

3. Monday


Monday is another task management tool. The platform offers a very simple yet effective solution to task management. There are plenty of reasons that teams use Monday.

Uploading tasks in a to-do list style makes it easy to break larger projects down into smaller tasks. Monday uses a color-based status to monitor the progress of tasks with just a glance. The platform also allows for integrations with other tools to bring tasks directly to you without the need for manual input, saving time.

4. Intercom


Intercom is one of the most popular live chat platforms for companies to use on their website. Most websites use live chat now as it’s a quicker and more convenient way for users to contact the support team.

This tool probably has some of the most customizable and intuitive features. Not only can you build a live chat system with automation and a bot, but you can also use Intercom to communicate via email, and build a FAQ page for your website.

5. Zendesk


Zendesk is one of the tools available that does the most for a company. The platform has an all-in-one feel to it, and can often be used to cover the whole of the customer services team.

With Zendesk, you can add live chat to your website, manage and ticket your emails, build and upload an in-depth FAQ page, manage phone calls, and manage social media. With all the important customer communication channels being brought under one roof, a team can respond to users faster than ever.

6. Google Workspace


Google Workspace is the most comprehensive tool on this list. However, this is a platform that many users may not know a company actually uses.

The platform brings Google to your organization. Google Workspace allows you to create email accounts using your company’s domain name and turns these into private Google accounts.

Related: The Best Google Teamwork Tools for Online Collaboration

This gives you access to all the Google services such as Drive, Docs, Slides, Photos, and all the others while allowing the company to manage each account.

Many organizations use Google Workspace behind the scenes for their emails, and file storage on the cloud.

How Many Startups Actually Use These Tools?

When it comes to how many startups use productivity tools, you’d probably argue that every startup does to one level or another. All startups use email at the very least, so their email client makes at least one tool that the company is using.

In terms of the list we’ve focused on in this article, all these tools are widely used by startups. Slack is used by 750,000 companies (2020), Asana by 50,000 (2018), Monday by 100,000 (2020), Intercom by 30,000+ (2021), Zendesk by 150,000 (2020), and G Suite by 6 million (2020). Across the board, the six tools we’ve looked at are used by approximately 7.1 million organizations.


And these six tools are just some of the most popular platforms out there. There are hundreds of other tools out there with high user numbers as well. So, when you consider this, inarguably you can see that so many startups really do use these tools.

So Are You Really a Startup?

Using or not using certain software cannot determine whether or not you are a startup company. The definition of a startup is "A newly established business".

If a company meets that definition, they are literally a startup. But, when you consider how integral many of these tools have become for startups, you must wonder what they’d do without them.

Ultimately, the tool that will be talked about is one that helps to increase their bottom line, improve the overall experience at work, and contribute to seamless team collaboration.

MUO – Feed

Data Transfer Object V3 Modernizes DTOs With PHP 8 Features

https://laravelnews.s3.amazonaws.com/images/spatie-dto-v3-featured.png

Spatie’s Data Transfer Object (DTO) package makes constructing objects from arrays a breeze, giving you confidence in the data contained therein. I’ve been a fan of this package since learning about the initial V1 release, and I hope you’ll consider this package for passing around data in your application.

The DTO package just released V3 with all of the PHP 8 goodies we’ve only dreamed of up to this point. For those just starting to use or consider PHP 8 in your projects, the source code of the V3 DTO package is an excellent resource with real-world examples of helpful PHP 8 features.

I want to congratulate the principal author Brent Roose and Spatie for moving forward with this excellent package with the features in the V3 release.

Here are some of the main features taken from the readme available in V3:

  • Named arguments
  • Value Casts – convert properties typed as a DTO from array data to the DTO instance automatically
  • Custom Casts – you can build your custom caster classes
  • Strict DTOs
  • Helper functions
  • Runtime type checks are gone in favor of PHP 8’s type system

If you want all the details of the above features, check out the project’s readme.

While the DTO package readme delves into the more complex use-cases this package supports, here’s a simple example back from V1 of what you might expect from this package for those not familiar with the DTO package:

class PostData extends DataTransferObject
{
    /** @var string */
    public $title;
    
    /** @var string */
    public $body;
    
    /** @var int */
    public $author_id;
}

$postData = new PostData([
    'title' => '…',
    'body' => '…',
    'author_id' => '…',
]);

$postData->title;
$postData->body;
$postData->author_id;

As you can see, we can pass array data to the constructor, which (at the time of V1) checks types at runtime and constructs a PostData instance or fails in an exception if the data is not valid.

With the release of typed properties in PHP 7.4 and named arguments and union types in PHP 8, Spatie’s V3 of the DTO package leverages many new language features. Taking the simple example above, here’s what it might look like in a PHP 8 version:

use Spatie\DataTransferObject\DataTransferObject;

class PostData extends DataTransferObject
{
    public string $title;
    public string $body;
    public int $author_id;
}

// Named arguments FTW
$post = new PostData(
    title: 'Hello World',
    body: 'This is a test post.',
    author_id: 1
);

echo $post->title, "\n";
echo $post->body, "\n";
echo $post->author_id, "\n";

The above example is simple but illustrates well how this package’s basics have evolved since V1, which supports PHP ^7.0. Note: given the above example, you might not even need to leverage the DTO package as PHP 8 takes care of the typing concerns and allows named arguments making a plain old PHP object (POPO) just as practical for this simple example.

If you haven’t tried Spatie’s DTO package, I hope even this simple example illustrates how you can know more about the data you transfer between objects. Imagine the above as an array of data:

$post = [
    'title' => 'Hello World',
    'body' => 'This is a test post.',
    'author_id' => 1,
];

$someObject->doStuff($post);

Let’s say that your doStuff implementation looks like the following to keep the example simple:

function doStuff(array $post)
{
    $title = ucwords($post['title']);
    $author = findAuthorById($post['author_id']);

    echo $title, "\n";
    echo htmlspecialchars($post['body']);
    echo $author['name'], "\n";		
}

As a consumer of doStuff(), you have no idea the shape of the required data without referencing the implementation of doStuff(). That means when you need to call doStuff(), you have to look at the function to know what array data to pass.

The maintainer of a naive doStuff() implementation assumes that the consumer is sending required data. Sending malformed or missing data results in undefined key errors that might not crop up until after you’ve shipped a feature. Or, if you’re paranoid, you might need to check everything before you use it:

function doStuff(array $post)
{
    if (empty($post['title'])) {
        throw new \Exception('Missing title');
    }

    if (empty($post['body'])) {
        throw new \Exception('Missing body');
    }

    if (empty($post['author_id'])) {
        throw new \Exception('Missing author_id key');
    }
    
    $title = ucwords($post['title']);
    $author = findAuthorById($post['author_id']);

    echo $title, "\n";
    echo htmlspecialchars($post['body']);
    echo $author['name'], "\n";		
}

Instead, you could guarantee the shape of data with a POPO or DTO (back in V1). It’s just that in DTO V2 and V3, some things are now handled natively through PHP 8’s language features instead of runtime checks:

function doStuff(PostData $post)
{
    $author = findAuthorById($post->author_id);
    
    echo $post->title, "\n";
    echo htmlspecialchars($post->body);
    echo $author->name, "\n";		
}

IDEs understand PostData, making it easy to both use and construct new instances. In this naive example, we know what data to expect, and the DTO package ensures this data is structured as expected when the object gets constructed.

While structured, typed data might seem like a trivial boilerplate to the veteran Java developer, PHP developers are more prone to seeing associative array data passed back and forth in an application. PHP 8 and this DTO package go a long way in providing more assurances of the data passed around in your PHP applications, which I believe makes you more productive and your code more confident.

Learn More

You can learn more about this package, get full installation instructions, and view the source code on GitHub. Freek Van der Herten and Brent Roose also wrote details of the Data Transfer Object v3 features if you’re looking for a more in-depth explanation and examples of the DTO package.

Laravel News