Axe throwing has become a popular sport. If you want to get into it, check out the WOOX Thunderbird Throwing Axe. IMG Tom Claycomb
U.S.A. -(AmmoLand.com)- As soon as I received a Press Release from Chip Hunnicutt about the WOOX throwing axe I knew that I had to check one out. So, long story short-before long I was throwing a WOOX Thunderbird Axe at a dead tree in the backyard. I’ve messed around on a small-time basis with throwing knives. Years ago I met a girl that was the knife throwing queen with a major knife company at the SHOT Show. She was really good and the traffic at her booth was slow so she took some time and worked with me a bit. I learned quite a bit from her.
I’m not a knife-throwing expert but from what I can tell, here are the basics. It is imperative to release the knife at the exact same spot every time. You can’t release it one time with your arm fully extended and the next time with your elbow half bent. Or else one time, the knife will hit on its point and the next time on the end of the handle.
The next big pointer. If your knife hits the target on the hilt of the handle, then you need to either step backwards or forwards, which will correct the point of impact. So really, in a nutshell, it is that simple.
Now let’s switch gears and jump into axe throwing. I like throwing an axe more because since it has a convex cutting edge, it has a larger sticking surface. So even if my throw isn’t dead on it is more likely to stick.
I’m not a competition axe thrower by any means, but by chance, this week, I was over in South Dakota and noticed that there is an axe throwing facility named Hub City Axe Throwing located in the Aberdeen mall. In a short amount of time, I was meeting with the owner Ryan Perrion. He is #75 in the WATL (WORLD AXE THROWING LEAGUE). There are two major leagues. The other one is IATF (INTERNATIONAL AXE THROWING FEDERATION). When covering a topic that I’m not well versed in, I interview an expert. In talking to Ryan, here are a few insights he shared.
He affirmed what I stated above that due to the convex edge, an axe is a little easier to stick than a knife.
He demo’d how important it is to throw from the exact same distance every time. He threw and had a marginal stick. Then he stepped back 6-inches further and threw with the exact same form. Solid stick. It was amazing how much of a difference that 6-inches made.
He suggested when getting an axe, be sure to get one that fits you. Look for the proper weight, handle size and length of handle that fits you personally. And if you plan on throwing competition, different leagues have different axe specs, so buy accordingly.
In competition they throw from 10 feet and 15 feet.
I don’t foresee myself doing competition axe throwing, but it was interesting talking to Ryan, and I learned a lot from him. So, if you’re interested in axe throwing competitions, check and see if there is a venue near you. Or, more likely, you’re like me and would just like to throw one and mess around. When you’re up in the mountains camping, you need to have some activities for everyone to do when lounging around camp. I think it’d be fun to set up a log to throw at. Or you could cut a wafer out of a log and spray paint some circles on the end and throw at that. That’d be a great way to pass time in camp.
So I think throwing a WOOX Thunderbird Axe could be great fun while hanging out in camp. In another few weeks, I’ll have an elk camp set up in the mountains for the archery season. I think it’ll be fun getting to practice more with my new WOOX Thunderbird Throwing Axe. Who knows, my next article may be on how I filled my elk tag with my new WOOX Thunderbird Throwing Axe. I can’t be much worse of a shot with it than I am with my bow!
So grab a WOOX axe and see if you can pick an apple off of your mother-in-law’s head. The MSRP on the WOOX Thunderbird Axe is $69.00. it is offered in purple, orange, blue or black. According to Ryan they make some decent axes. I’d recommend you also get the leather sheath for $29.00, and as is usual, we will close with the company comments.
The Thunderbird from WOOX is a dedicated axe for throwing, featuring a lightweight head for more accuracy and precision. The tomahawk style is just as home as a one-handed wood cutter for those times when you need to make quick work of chopping projects.
The 14” handle is real American Appalachian hickory and the Italian tempered carbon steel head comes in your choice of four distinct colors, perfect for teams or distinguishing singles competition throwing. The Thunderbird meets ALL the National and International competition requirements (WATL & IATF).
Thunderbird accessories:
– Sheath – protect your sharp edge and prevent unintended cuts
– Whetstone Puck – maintain your Thunderbird’s edge with this dual grit whetstone
About Tom Claycomb
Tom Claycomb has been an avid hunter/fisherman throughout his life as well as an outdoors writer with outdoor columns in the magazine Hunt Alaska, Bass Pro Shops, Bowhunter.net, and freelances for numerous magazines and newspapers. “To properly skin your animal you will need a sharp knife. I have an e-article on Amazon Kindle titled Knife Sharpening for $.99 if you’re having trouble.”
Bash scripts come in handy for automating tasks, and you’ll find they’re great for building simple command line applications. The Bash shell interprets Bash scripts, so you won’t need to install any dependencies to write and run them. Bash scripts are also portable since most Unix-based operating systems use the same shell interpreter.
Knowledge of Bash scripting is a must for every developer, especially if you work with Unix-based systems.
Variables in Bash
Bash variables are case-sensitive. To declare variables, use an equals sign (=) with the name on the left and value on the right:
STATE=Washington
The value this declaration assigns to STATE is a single word. If you need spaces in your value, use quotes around it:
STATE="North Arizona"
You’ll need to use a dollar sign ($) prefix to reference variables in other variables or statements:
STATE=Washington LOCATION="My Location is $STATE"
Printing Values in Bash
There are several ways you can print variables in Bash. You can use the echo command for basic output or the C-style printf command for string formatting.
STATE=Washington LOCATION="My Location is $STATE" echo$LOCATION
After declaring the STATE variable, this script defines LOCATION by referencing STATE. If then uses echo to print the final value of the LOCATION variable.
The printf keyword allows you to use formatting verbs to output data. The string formatting verbs are similar to the ones in C and Go but with limited verbs.
Verb
Functionality
%c
prints single characters
%o
prints Octadecimals
%s
prints strings, independent of casing
%x
prints lowercase hexadecimal
%X
prints uppercase hexadecimal
%d
prints integers
%e
prints scientific notion floats in lowercase
%E
prints scientific notion floats in uppercase
%f
prints floating point numbers
%%
prints a single percentage symbol.
Here’s an example of using a verb with the print keyword.
STATE=Lagos printf "My Location is %s" $STATE
The printf function would substitute the STATE variable in the position of the %s verb, and the output would be “My Location is Lagos”.
You can make comments in Bash with the hash or pound (#) symbol. The shell automatically ignores comments.
#!/bin/bash
There are no multi-line comments. Most IDEs and text editors allow you to comment with the Ctrl/Command + forward slash(/) shortcut. You should be able to use the shortcut to create multiple single-line comments.
Receiving User Input in Bash
Like many other programming languages, you can receive user input in Bash to make your programs/scripts more interactive. You can use the read command to request the user’s input.
read response
In this case, the response variable will hold the user’s input on delivery.
echo "What do you want ?: " read response echo $response
The user input request will be on a new line in the example above.
You can add the -n flag to the echo print statement to retain the line where the user enters input.
echo -n "What do you want." read response echo $response
Declaring Arrays in Bash
Arrays in Bash are just like most languages. You can declare an array variable in Bash by specifying the elements in parentheses.
Accessing an array via reference to the variable name would fetch the first element. You can access the entire array by using the asterisk sign as the index.
echo ${Countries[*]}
You can also specify the index of the array to access a specific element. The index of an array starts at zero.
echo "${Countries[4]}"
Conditional Statements in Bash
Bash provides conditionals for decision-making in programs.
Here’s the anatomy of an if-else statement in Bash. You’ll have to use the semi-colon to specify the end of the condition.
if [[ condition ]]; then echo statement1 elif [[condition ]]; then echo statement2 else [[condition ]]; then echo statement3 fi
You must end every if statement with the fi keyword.
if [ 1 == 2 ]; then echo one elif [ 2 == 3 ]; then echo two else [ 4 > 3 ]; echo "correct, 3" fi
You can use case statements in your Bash programs using the case keyword. You’ll have to specify the pattern followed by ending parentheses before the statement.
Here’s an example of the C style for-loop. For-loops must end with the done keyword, and you must end the for statement with a semicolon followed by the do keyword.
for ((a = 0 ; a < 10 ; a+2)); do echo$a done
The range for loop comes in handy for working with files and many other operations. You’ll need to use the in keyword with the range for-loop.
for i in {1..7}; do echo$1 done
Here’s a simple infinite loop to demonstrate Bash while loops in action.
name=1 while [ 1 -le 5 ] do echo$name done
The -le in the condition statement is the binary operator for less than.
Functions in Bash
You don’t need keywords to declare functions in Bash. You can declare functions with the name and then parentheses before the function’s body.
print_working_directory() { echo$PWD } echo "You are in $(print_working_directory)"
Functions can return variables in Bash. All you need is the return keyword.
print_working_directory() { return$PWD }
The print_working_directory function returns the working directory of the file.
You Can Write Shell Scripts in Other Languages
Bash isn’t the only language you can use to interact with your operating system’s shell or build command-line applications. You can use many other languages like Go, Python, Ruby, and Rust.
Many operating systems have Python3 pre-installed, and Python is a prevalent language. If you need even more functionality than Bash scripts can offer, consider using Python.
Everyone one of you reading this has had a bad fast food experience. Orders are wrong. Food isn’t cooked the way you want. It looks nothing like the photo. We’ve all had these first-world problems. But we don’t get so angry we call the cops. Nor do we get so angry we forget we are wanted for murder before calling the cops. Antoine Sims was that angry, and he’s not loving it.
Not while screaming like a little girl after getting tased. After running from the cops. After realizing maybe calling them wasn’t one of his better ideas.
Dude was wanted for murder but called the cops on McDonalds serving him cold fries. Tried to run for it. Didn’t go well
The details of why he was wanted are horrible. Sims and some other loser are accused of setting fire to a car with a woman’s body inside after a botched drug deal led to a gunfight. He failed to appear for a 2018 court date over it.
It all explains why Sims would call the cops over his cold french fries and then say he was afraid of the cops when they showed up. Somewhere between telling the cops, “I try the fries the fries, they’re lukewarm but they’re not hot," and yelling as a sudden jolt of electricity runs through his body, Antoine realized his tactical era.
All over french fries. Overrated french fries, too.
The Louder with Crowder Dot Com Website is on Instagram now!Follow us at @lwcnewswire and tell a friend!
Giga-Chad Traffic Pole VAPORIZES Criminal! | Louder With Crowder
We’ll start by creating a new test file. Please execute the following command in your terminal:
php artisan make:test UserTest
A new test file should be created at tests/Feature/UserTest.php.
Heads up – Resetting the database
If your code and tests play with the database, you should reset your database after each of your tests to ensure that one test cannot affect the results of another one. Laravel makes it effortless by providing a trait that you can add to your test classes.
Please add the following trait in the UserTest.php file:
The default test file already covers a test for a GET request. Thus, we can directly write a test for a POST request.
When the user submits the form from the browser, a POST request is made with the inputs and values. We are going to simulate the same thing in our tests.
Please append the following code to the UserTest.php file:
Laravel provides an easy way to make a POST request from your test files using the post() method. Using that, we make the request and verify that user details are added to the database and the response is a redirect with the proper message in the session.
Wasn’t this straightforward? Let’s try one more.
Test for the validation
How about adding a test to make sure that our validation works as expected? Please append the following code to the UserTest.php file:
Here, we pass invalid data for the form inputs and confirm (assert) that there is a redirect response (HTTP status code 302) and that there are validation errors in the session.
Test for the unique email address
The business requirement is that the email address of each user has to be unique so let us add a test for the same. Append this test to the UserTest.php file:
This test uses Laravel Factory to add a user to the database and then tries to make a POST request with the same email address. Let us run tests and see the results.
Oops, it failed. And the reason? We missed adding the unique validation in our code.
The Fix
Now your test is guiding you with the development. (Yes TDD!)
Please make the following update in the routes/web.php file:
Once updated, give yourself a pat on the back and run the tests again (php artisan test)
What more?
Did you realize you are now officially a developer who writes automated tests? Congrats!
Need more examples? Check this directory from the official Laravel repository for tests related to various modules.
The goal of this article is just to get you started with writing tests. Not to cover different use cases or scenarios. Hence, I limit the practical coding here and would like to share a few other things to help you progress with it.
Patterns that can help you
Many developers aren’t sure for which parts of their code should they write tests. The simplest answer is: Try to write automated tests for all the functionality that you check while manually testing your web app.
In this example, we would have checked the DB entry, the validation messages, and the redirect while manually testing the web app. And that is what our automated tests covered.
Here are a couple of patterns to help you plan your tests:
1. Given-When-Then
2. Arrange-Act-Assert
Both are similar so you can use any of them. The idea is:
First, you set the scene (Add existing DB records, log in a user, etc.)
Then you take an action (Visit a URL, submit a form, etc.)
Finally, you verify the results/effects (A DB entry, a session call, response status code, etc.)
This way can generally help you in writing most of the test cases.
What we covered in this article are Feature tests. There are many other types of tests (Unit tests, Feature tests, Integration tests, Acceptance tests, etc.).
Do not hurry to learn/use all of them, you don’t have to. You will feel the need yourself if/when the time arrives.
Topics like mocking and stubbing fall in the same category. Believe me, it is not compulsory to use them. But keep in mind they are quite handy for medium to big-size projects. We use them in our projects and can’t live without them.
A Note on PEST
We use PEST for writing tests but I decided not to include that in this article to keep things simple. I wish (and am sure) it would come out of the box with Laravel.
To The Moon
I hope this article gets you started with writing tests and you never stop in the future. Feel free to comment below in case of any questions. May those tools give you more testing features 😉
And if any of your friends are also giving excuses to start writing tests, how about sharing this article with them for the push?
Volquartsen Firearms is very well known in the rimfire market for their high-quality, accurate pistols often used for varmint hunting or competition shooting. Volquartsen has just announced the addition of the new Scorpion-X to their line of complete pistols. The new Scorpion-X uses the all-new Volquartsen LLV-X upper which features multiple mounting hole locations so […]
We are happy to announce the new release of our flagship solution for MySQL – dbForge Studio for MySQL – which is now available on Linux and macOS! Check out the updated features and improvements. Getting Started and Video Tutorials When you need to learn how the product or its specific feature works, you as […]
Following the tragedy in Uvalde, Texas, gun control advocates have taken the anti-gun narrative to a fever pitch. They insist that the only way to prevent mass shootings is to institute stricter gun control on law-abiding citizens. However, when a good guy with a gun stopped a bad guy with a gun in an Indiana mall, they disregard it as isolated. But a Crime Prevention Research Center study proves it to be quite common.
Study Proves the Good Guy with a Gun Theory
The gun control lobby has spent years trying to create a narrative that guns are never used for self-defense. They have dedicated a plethora of articles across liberal media to help build this false premise. Likewise, they insist that the only people who should be armed are police officers. And then they attend a “defund the police” rally.
Not to open a still healing wound, but we saw how trained law enforcement handled Uvalde. It wasn’t a shining endorsement for disarming citizens and making them rely on that kind of response.
This isn’t meant as an attack on law enforcement officers. They have a very hard and dangerous job. Not to mention thankless in today’s society. I am just demonstrating that you are your own last line of defense. As the saying goes, “when seconds count, police are just minutes away.”
However, in stark contrast is the recent incident in the mall in Indiana. After an active shooter opened fire on unsuspecting victims in a food court, it only took an armed citizen 15 seconds to stop it. Although, unfortunately, three people were killed, it could’ve been far worse if not for the good guy with a gun.
There are many cases like this where a concealed carry permit holder acted in their own self-defense or the defense of others. You may have noticed that we have been compiling stories of recent cases where guns save lives. This is not by accident. It’s an effort to create a one-stop reference library of evidence when gun grabbers try to tell you otherwise.
An Ongoing Study
Well, we aren’t the only ones providing such a resource. The Crime Prevention Research Center has a running list of cases where concealed handgun permit holders have stopped likely mass shootings. In fact, the list was recently updated to include the case in Indiana.
The post was originally written in April of 2015 but is still periodically updated. However, it states that lack of news coverage on the topic means they probably do not have all the cases. Still, 60 cases over seven years are nothing to take lightly. That is a lot of mass shootings that could have been far worse.
But it’s important to note that the list only compiles instances where firearms were used to stop likely mass shootings. It does not include the use of firearms in the act of self-defense.
When it comes to self-defense, American Gun Facts states, “The best estimates are that guns are used to deter or thwart crime between 500,000 and 2.8 million times per year, but the more likely answer is probably somewhere in the middle. A 2021 survey estimated that guns are used 1.67 million times per year in self defense in the United States.”
No Shortage of Examples
As I mentioned, there are 60+ cases to dig through. So, you will have no shortage of examples for your gun control friends. The list even includes some examples you may recognize from our reporting. Such as the Indiana case and the case of the woman who prevented a mass shooting at a graduation party.
Here are a few other examples:
“Phenix City, AL, April 13, 2022 (WTVM, Ledger-Enquirer) Two suspects went to the truck shop over a dispute from earlier in the day. One got out of his vehicle and begin to shoot at four people standing outside the business. One of the intended victims with a concealed handgun permit had his own firearm and returned fire, striking both suspects. The business owner Paul Thrasher said ‘if [they] would not have been [sic] returned fire, he would have advanced on us we would have had a fatality. Thank God for my employees.’”
“Portland, OR, February 19, 2022 A homeowner allegedly confronted participants at a racial justice demonstration Saturday night before pulling out a handgun and shooting multiple people in the crowd, leaving one woman dead and several others injured. The shooting ended when a person with the group of demonstrators, who is licensed to conceal carry a firearm, fired back, striking the homeowner in the hip.”
“Syracuse, NY, August 31, 2021 The District Attorney credited a property manager with saving the lives of several individuals after he pulled a legally possessed 9mm handgun and fatally wounded a man who opened fire on a crowd outside a building.”
You Can Take Your Chances, and I’ll Take a Good Guy with a Gun
You know the saying, “the only thing that stops a bad guy with a gun is a good guy with a gun.” It’s not just a bumper sticker, it is founded on fact.
Case after case proves that guns save lives, specifically good guys with guns. Not everyone can live in a gated community with a security guard or ten. Some of us live in the real world where people are shot and killed by criminals as a result of rising violent crime and soft-on-crime policies.
As crime increases and gun control rhetoric dominates every TV across the nation, you should understand the facts. If you still support gun control, that is your right. We live in a country where diversity of thought is encouraged, and you are welcome to lead by example and disarm yourself.
You can take your chances, but I will take a good guy with a gun.
Many Mailtrap users create their apps with PHP and the vast majority of them choose Laravel. It is simple and in addition, is covered in-depth by documentation and tutorials. However, we still observe numerous questions on sending emails with Laravel, testing them, as well as Mailtrap configurations. We have analyzed the most popular requests on Stack Overflow, Reddit as well as Google search and in this post we will provide you with the list of answers. How to send an email with Laravel? How to send a Laravel email via Mailtrap? Why isn’t Laravel mail working? Let’s figure it out.
Why Laravel and how it works
Laravel is a PHP framework that stands out for its simplicity, modernity, and connectivity. Probably, those characteristics make it especially popular among startups.
Laravel is widely used for building websites, marketplaces, web apps, and even frameworks.
The mail function is essential for these tasks, to register or notify the users, so it’s native in Laravel and provides a wide range of capabilities:
A list of integrations for sending emails through local or cloud-based services. Now Laravel proposes using drivers for SMTP, Mailtrap Email Delivery, Mailgun, SparkPost, Amazon SES, and sendmail.
Options for queueing emails.
Markdown support, which is available in a quite few frameworks. It lets you create beautiful templates and easily include buttons, tables, or panels.
Regular plain text and HTML messages.
Attaching files of different formats and MIME types, as well as raw data, inline attachments, and even embedding raw data into mail templates.
Templating system, which lets you use various templates and configure the view.
Message previews in-browser.
In addition, there are some noteworthy options:
Localization methods, so that you can set the desired language for a specific user.
Local development mailing. This is how you can prevent sending test emails to real inboxes. Mailtrap is one of the preferred options.
What you need to know about Laravel Mail
You will intuitively find all guidelines on the Laravel website and the educational Laracasts portal. That is why we rejected the idea of creating our own tutorial. For a better understanding, we decided to outline some basic principles, provide you with examples of creating an email in Laravel, and give you some tips and explanations.
Building email in Laravel
Here are a couple of basic things to keep in mind.
Laravel includes its own command-line interface called Artisan. (Yes, it definitely refers to their slogan “The PHP framework for web artisans”). It provides a bundle of useful commands, for email creation in particular. To get all available commands, type:
php artisan list
Each email category can be represented as a “mailable”. It’s a class that is responsible for building a specific email message using a set of methods.
For example:
php artisan make:mail NewUserNotification
command generates a class, which you’ll find at ‘app/Mail/NewUserNotification.php. The build() method of this class creates email messages:
public function build()
{
return $this->from('example@example.com')
->view('emails.newuser');
}
This way, we have written a mailable with a build() method. Of course, it’s a minimal example, but you can make the necessary configuration and the next time you need to send it again, you will just type:
To send an email, you have a bunch of options. Laravel’s creators recommend using one of the API based drivers: Mailgun, SparkPost, or Amazon SES.
Laravel 7.0 introduces multiple drivers. It means that you can set one of the drivers as a default one in your mail configuration file (Mailgun, for example), but configure sending particular types of messages (let’s say, notifications) with SparkPost.
For configurations, follow this section of the Laravel Documentation.
You are also free to use any SMTP server you prefer, like Gmail. The related configurations are made in the config/mail.php file. In the default Laravel setup, the email configuration is read from environment variables so to edit them, you should save your changes to the .env file (you will find it in the root directory).
The Mailtrap SMTP server is one of the recommended SMTP methods in Laravel. It helps you avoid sending test emails to real inboxes by accident. It is designed to catch these interim emails and help you debug them. With Mailtrap, your email will never land in the real inbox in any of the email clients.
So, if you are ready to send your message to your own or even your customer’s inbox, don’t forget to replace the configuration with that of the real server. For example:
And if you’re using Mailtrap Email Delivery as your sending solution, we provide the SMTP configuration for you. Just copy-paste the configuration listed in the app, verify your domain, and you’re good to go.
Laravel versions
A new version of Laravel is released every six months. Then bug fixes are provided for another six months while security fixes are delivered within a year. Also, starting from 5.1, Laravel offers long-term support (LTS) version, with bug fixes valid for two years and security fixes – for three.
For July 2020, Laravel 7.0 is the latest released version.
We observe that in 2020 users were still working with Laravel 6.2, 5.8, 5.6, 5.4, 5.3, or even 5.2 versions. But versions below 5.5 (LTS) were no longer supported:
Sometimes, the use of the old versions might result in some performance issues. Most likely, you might just miss some functionality and waste your time. Here is a list of some important updates delivered in 6 and 7 versions, which affect email sending options.
Laravel 6 (LTS) introduced semantic versioning, compatibility with Laravel Vapor, enhanced authorization responses, job middleware, lazy collections, and subquery improvements, as well as other bug fixes and usability improvements.
Laravel 7 delivered Laravel Sanctum (an authentication system), Blade component tags, a developer-focused HTTP client, first-party CORS support, multiple mail drivers, a new artisan test command, along with other bug fixes and usability improvements.
How to send email in Laravel 7.0 using SMTP
To sum up, let’s review an example of coding a message in Laravel 7.0 and testing it with Mailtrap’s fake SMTP service. We will take advantage of Laravel’s awesome features like Blade templates, Mailable class, and Markdown support.
We assume that you have been already using Laravel for building your application. If you were working in one of the previous versions, update your laravel/framework dependency to7.0.*in your composer.json file, as recommended in the official guide.
Let’s start by defining an SMTP server and setting the mailing configuration. We prefer to test our notifications with Mailtrap first, to make sure our code works fine and the content of the messages is rendered properly.
Mailtrap is a default server in Laravel, so you need just to type in your credentials. You will find them in the SMTP Settings tab of your Inbox. Also, you can use Integrations data from the same tab. Choose Laravel from the list, copy the following details, and paste them to your .env file:
This way, we have created a Mailable class, with the name MailtrapExample.php. Now we should find it in the Mail directory in app/Mail. We have a template, which contains basic needed functions so that we should just modify it.
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class MailtrapExample extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('mail@example.com', 'Mailtrap')
->subject('Mailtrap Confirmation')
->markdown('mails.exmpl')
->with([
'name' => 'New Mailtrap User',
'link' => '/inboxes/'
]);
}
We’ve added a sender, a subject, a couple of variables and introduced the Markdown support.
Now it’s time to create the body of our message. For this purpose, we will use a Blade template.
We have specified that our mailable is located in the mails.exmpl. Now we need to create a ‘mails’ directory with a blade template file ‘exmpl.blade.php’. inside. Templates represent views in Laravel, so keep the template file in the resources/views/mails directory.
@component('mail::message')
Hello ****,
Thank you for choosing Mailtrap!
Click below to start working right now
@component('mail::button', ['url' => $link])
Go to your inbox
@endcomponent
Sincerely,
Mailtrap team.
@endcomponent
Our simple configuration is done, and we can move forward with sending our message. Specify the route in theroutes/web.php:
<?php
use App\Mail\MailtrapExample;
use Illuminate\Support\Facades\Mail;
Route::get('/send-mail', function () {
Mail::to('newuser@example.com')->send(new MailtrapExample());
return 'A message has been sent to Mailtrap!';
});
Run your application. Usually, it should be php artisan serve in development, then go to /send-mail path of your application in the browser (http://127.0.0.1:8000/send-mail when running with php artisan serve.)
Note that starting from the 5.8 version, Laravel is capable of serving multiple applications. Earlier, only port 8000 was available but now serves scans for free options up to 8009.
That’s it. Your application will send a message and you will see it in your Mailtrap inbox:
Verify if the result matches your expectations: whether all elements are displayed correctly and links work properly. View the Check HTML and Analysis tabs in Mailtrap to make sure your messages won’t be considered spam and will be rendered correctly in most email clients.
Once you are satisfied with the results of tests, replace SMTP configurations with your production server or configure any other option to send emails to real inboxes.
Social login is now an essential part of any site which performs user authentication. It does not need to replace the standard form based authentication, quite the contrary, social login complements it. Login with social accounts is a straightforward process and it saves the users a lot of time, as they won’t need to fill the whole form. They just sign up with their social account and they can log into the website with just a few clicks.
OAuth is an open standard protocol for access delegation, commonly used as a way for internet users to grant websites or applications access to their information on other websites but without giving them the passwords. Laravel Socialite package provides a simple, fluent interface to authenticate with OAuth providers. It currently supports authentication via Facebook, Twitter, LinkedIn, Google, GitHub, GitLab and Bitbucket.
Prerequisites
A Laravel project is required to use Socialite package. Take a look on how to create your first Laravel project, if you don’t have any yet. The latest stable and compatible version is recommended to be installed for the both: framework and PHP.
To get started with Socialite, use the Composer package manager to add the package to your project’s dependencies:
composer require laravel/socialite
Registering with OAuth providers
Before implementing and using Socialite, you will need to generate credentials for OAuth providers your application want to operate with. Typically, these credentials may be retrieved by creating a developer application within the service you will be authenticating with.
Detailed explanation on how to retrieve credentials for different services can be found below:
Configuring your application
Credentials generated in the step above should be placed in your application’s config/services.php configuration file. Depending on the providers you want to use, credentials are defined with one of the following keys : facebook, twitter-oauth-2, linkedin, google, github, gitlab or bitbucket.
That’s an example of definition of Google OAuth credentials in config/services.php configuration file.
Define environment variables
Environment variables provide another way to specify configuration options and credentials. As you can see, the definition of credentials in config/services.php is using environment variables and it means that you need to define them in your .env file:
Define both routes in the project routes/web.php file with desired options (prefixes, names, middleware, etc…).
Preparing your database
Once the user has been retrieved from the OAuth provider, you may determine if the user exists in your application’s database and authenticate the user. If the user does not exist in your application’s database, you will typically create a new record in your database to represent the user. OAuth callbacks include a string that represents a unique identifier for the user on the OAuth platform.
In case of using MySQL database, a new varchar column can be added to the users table. It will contain OAuth identifier and help us to find the user in future queries, i.e., facebook_id, twitter_id, google_id, etc... You may want to save user token, refresh token and token expiration date too. Everything depends on the use case.
Implementing Socialite controller
We’ve previously configured two routes for the OAuth provider and both routes are pointing to the same controller. Socialite helps to abstract the complicated OAuth logic making the implementation quite standard, with slight differences for different providers. A template has been defined and it can be used for all available OAuth2 providers changing the class constant and completing TODOs that depends on your application.
<?php namespace App\\Controllers;
use Illuminate\\Http\\Request; use Illuminate\\Http\\RedirectResponse;
use Laravel\\Socialite\\Facades\\Socialite; use Laravel\\Socialite\\Two\\User as SocialUser;
public function redirect(): RedirectResponse { return Socialite::driver(self::OAUTH_PROVIDER)->redirect(); }
public function callback(Request $request): RedirectResponse { /** @var SocialUser $socialUser */ $socialUser = Socialite::driver(self::OAUTH_PROVIDER)->user();
if ($socialUser->getEmail() === null) { // TODO Missing email, redirect to manual registration page }
try { // TODO Get user from database using ID or email address // TODO Throw UserNotFoundException if user does not exist // TODO Update user attributes (if needed) } catch (UserNotFoundException $e) { // TODO Create new user record in the database } finally { // TODO Authenticate existing or new created user in the system }
// TODO redirect authenticated user } }
First let’s check what kind of information social user variable contains:
$socialUser->getId() // User identifier from OAuth provider $socialUser->getNickname() // User nickname or null $socialUser->getName() // User name concatenated with surname in some cases $socialUser->getEmail() // User email address $socialUser->getAvatar() // User avatar URL
Additional information can be gathered for Google OAuth users:
$socialUser['email_verified'] // User email verification flag (boolean)
Generally, for OAuth2 providers, token information is available too:
As you can see it’s very easy to setup any provider and the code for all of them is quite similar.
Conclusion
Login with social accounts is a straightforward process and at the same time it improves the user experience. Officially Socialite plugin only supports popular platforms for OAuth but you can find non-official implementations of other platforms too.