Tame Black Friday Gremlins — Optimize Your Database for High Traffic Events

Tame Black Friday Gremlins — Optimize Your Database for High Traffic Events

https://ift.tt/3f68hyu

Optimize Your Database for High Traffic Events

Optimize Your Database for High Traffic EventsIt’s that time of year! The Halloween decorations have come down and the leaves have started to change and the Black Friday/Cyber Monday buying season is upon us!

For consumers, it can be a magical time of year, but for those of us that have worked in e-commerce or retail, it usually brings up…different emotions. It’s much like the Gremlins — cute and cuddly unless you break the RULES:

  1. Don’t expose them to sunlight,
  2. Don’t let them come in contact with water,
  3. NEVER feed them after midnight!

I love this analogy and how it parallels the difficulties that we experience in the database industry — especially this time of year. When things go well, it’s a great feeling. When things go wrong, they can spiral out of control in destructive and lasting ways.

Let’s put these fun examples to work and optimize your database!

Don’t Expose Your Database to “Sunlight”

One sure-fire way to make sure that your persistent data storage cannot do its job, and effectively kill it is to let it run out of storage. Before entering the high-traffic holiday selling season, make sure that you have ample storage space to make it all the way to the other side. This may sound basic, but so is not putting a cute, fuzzy pet in the sunlight — it’s much harder than you think!

Here are some great ways to ensure the storage needs for your database are met (most obvious to least obvious):

  1. If you are on a DBaaS such as Amazon RDS, leverage something like Amazon RDS Storage Auto Scaling
  2. In a cloud or elastic infrastructure:
    1. make sure network-attached storage is extensible on the fly, or
    2. properly tune the database mount point to be leveraging logical volume management or software raid to add additional volumes (capacity) on the fly.
  3. In an on-premise or pre-purchased infrastructure, make sure you are overprovisioned — even by end of season estimates — by ~25%.
  4. Put your logs somewhere else than the main drive. The database may not be happy about running out of log space, but logs can be deleted easily — data files cannot!

Don’t Let Your Database Come in “Contact With Water”

We don’t want to feed or allow simple issues to multiply. Actions we take to get out of a bind in the near term can cause problems that require more attention in the future — just like when you put water on a Gremlin, it will multiply!

What are some of these scenarios?

  1. Not having a documented plan of action can cause confusion and chaos if something doesn’t go quite right. Having a plan documented and distributed will keep things from getting overly complicated when issues occur.
  2. Throwing hardware at a problem. Unless you know how it will actually fix an issue, it could be like throwing gasoline on a fire and throw your stack into disarray with blocked and unblocked queries. It also mandates database tuning to be effective.
  3. Understanding (or misunderstanding) how users behave when or if the database slows down:
    1. Do users click to retry five times in five seconds causing even more load?
    2. Is there a way to divert attention to retry later?
    3. Can your application(s) ignore retries within a certain time frame?
  4. Not having just a few sources of truth, with as much availability as possible:
    1. Have at least one failover candidate
    2. Have off-server transaction storage (can you rebuild in a disaster?)
    3. If you have the two above, then delayed replicas are your friend!

Never “Feed” Your Database After “Midnight”

What’s the one thing that can ensure that all heck breaks loose on Black Friday? CHANGE is the food here, and typically, BLACK FRIDAY is the midnight.

Have you ever felt like there is just one thing that you missed and want to get off your backlog? It could be a schema change, a data type change, or an application change from an adjacent team. The ‘no feeding’ rule is parallel to CODE FREEZE in production.

Most companies see this freeze start at the beginning of November when the most stable prod is the one that is already out there, not the one that you have to make stable after a new release:

  1. Change Management is your friend; change that needs to happen should still have a way to happen.
  2. Observability is also your friend; know in absolute terms what is happening to your database and stack so you don’t throw a wrench in it (Percona Monitoring and Management can help).
  3. Educate business stakeholders on the release or change process BEFORE the event, not DURING the event.
  4. Don’t be afraid to “turn it off” when absolute chaos is happening. Small downtime is better than an unusable site over a longer period of time.

Conclusion

Black Friday, Cyber Monday, and the Holidays can be the most wonderful time of the year — and now that we’ve covered the rules, some of the “Gremlins” can stay small and fuzzy and your business won’t get wrecked by pesky database issues or outages.

How Percona Can Help

Percona experts optimize your database performance with open source database support, highly-rated training, managed services, and professional services.

Contact Us to Tame Your Database Gremlins!

technology

via MySQL Performance Blog https://ift.tt/1znEN8i

November 17, 2020 at 10:19AM

Things to Consider When Building A Reliable AR 15 Rifle

Things to Consider When Building A Reliable AR 15 Rifle

https://ift.tt/32QQNBq

Things to Consider When Building A Reliable AR 15 Rifle
By RAR Guns

RAR Independence XRT Rifle
RAR Independence XRT Rifle

Castle Rock, CO –-(Ammoland.com)- I often see articles and post explaining how to assemble an AR15 rifle. While I find many of these articles to be very informative, most don’t touch on the details that are required to build a reliable, accurate rifle.

First, let’s examine what a reliable AR15 must be able to do. A reliable Ar15 must first and foremost fire every time you pull the trigger. Whether in a life or death situation, competition shooting, or just plinking, your weapon needs to work properly. It must also hit what you are aiming at.

One of the main reasons an Ar15 will miss fire is that poor quality parts were used. Saving a few dollars on a bolt assembly can mean the difference between a reliable rifle and one that consistently has problems.

When building a rifle from scratch, you should have a sort of blueprint. You should know what parts you are going to use from the outset as opposed to just buying parts as you find them on sale. This is not to say you have to buy all your parts at once. But instead, know what you going to buy and why you’re using that particular part.

I have seen several instances where someone bought AR rifle parts because it was cheap. This later caused problems in the rifle. One guy bought a lightweight buffer and buffer spring because it was very cheap. Upon completing the rifle, he went to the range only to find that he couldn’t get two rounds in a row through it because it was short cycling. The buffer and spring did not match the rest of the parts he was using.

You should know how and what you will be using your rifle for. This will affect what parts you use to build the rifle. For instance, if you plan to shoot steel cased ammo in your rifle, you will have much more success with a 5.56 NATO chambered rifle than a .223 chambered rifle.

You will also need a heavy-duty SOPMOD style ejection spring kit. This will ensure that you get a successful shell extraction each and every time you fire the weapon.

Consider AR Rifle Accuracy when Building A Reliable AR 15 Rifle

Ar15 Lower Parts
Enhanced Ar15 Parts

Another thing to consider is how important accuracy is. AR15s vary in accuracy by quite a bit. They can range anywhere from ¼ MOA to 3 MOA. A lot of the accuracy obviously has a lot to do with the barrel you choose. A barrel does not have to cost $500.00 to be a good, accurate barrel. You can achieve a sub 1 MOA with a mid range cost barrel. And contrary to popular belief, a longer barrel is not a whole lot more accurate than a shorter barrel in most cases.

What you may gain in accuracy will be lost in mobility and weight.

When thinking about how accurate your weapon needs to be, consider the mission of the weapon. If it is a combat or tactical competition rifle, you probably what something you can group a lot of rounds quickly in a small area as opposed to one shot at a time in a ¼ inch hole. There are several things that can help in this area. A gas piston system will help with faster target reacquisition as will a good muzzle break/compensator. There are several products available to modify the receiver extension/buffer tube as well that will reduce felt recoil.

A high-quality AR15 trigger and enhanced lower parts kit can also aid in acquiring your target quickly. I don’t recommend a two-stage trigger for a combat or tactical competition rifle. Instead, I like a short pull single-stage trigger with about 4 lbs. or less of resistance.

A reliable feed is another area that needs to be addressed. There are a lot of low cost lower receivers on the market that are very good. There are a few that are only good for paperweights. A good AR15 lower should either be forged or billet. Never use a cast lower receiver. They are unreliable and weak.

A quality BCG or Bolt Carrier Group is very important to reliable feeding. This is what is going to push the round into the chamber and lock it into place. A poorly manufactured BCG will be unreliable and possibly dangerous to the operator and other friendlies in the area.

The upper receiver may or may not have M4 style feed ramps. In today’s market, I see no reason not to have M4 feed ramps at least in the chamber. One problem we see a lot is the fit between the M4 cuts on the upper receiver and the M4 cuts on the chamber matching up. An improper fit will cause miss feeds and jams. This can be corrected a couple different ways. If you’re mechanically inclined, you may be able to fix the problem yourself. If not, take your rifle to a qualified gunsmith or armorer to fix the problem.

These are just a few things that should be considered when starting to build your own AR15 rifle.

RAR Guns will at no charge or obligation, give free AR building advice and help to anybody who wants it. No strings attached.

RAR Independence XRT Rifle
RAR Independence XRT Rifle

About:

RAR Guns. Home of the best AR 15s in the world. We don’t just assemble parts. We measure and test each part before it is installed. Then each part is function tested to ensure proper operation. We have several AR15 models to choose from and we also build to your custom specifications. We warranty our AR15 rifles for workmanship for a full year no questions asked. Our AR15 rifles will even perform with most Russian, steel cased, and polymer-coated ammo. If it breaks or has a malfunction within one year of purchase, we will correct the problem for free.

The post Things to Consider When Building A Reliable AR 15 Rifle appeared first on AmmoLand.com.

guns

via AmmoLand.com https://ift.tt/2okaFKE

November 16, 2020 at 08:26PM

Real Python: Python and PyQt: Creating Menus, Toolbars, and Status Bars

Real Python: Python and PyQt: Creating Menus, Toolbars, and Status Bars

https://ift.tt/3kI1ZXi

When it comes to developing graphical user interface (GUI) applications with Python and PyQt, some of the most useful and versatile graphical elements that you’ll ever use are menus, toolbars, and status bars.

Menus and toolbars can make your applications look polished and professional, presenting users with an accessible set of options, while status bars allow you to display relevant information about the application’s status.

In this tutorial, you’ll learn:

  • What menus, toolbars, and status bars are
  • How to create menus, toolbars, and status bars programmatically
  • How to populate Python menu and toolbar using PyQt actions
  • How to use status bars to display status information

In addition, you’ll learn some programming best practices that you can apply when creating menus, toolbars, and status bars with Python and PyQt. If you’re new to GUI programming with PyQt, then you can check out Python and PyQt: Building a GUI Desktop Calculator.

You can download the code and resources for the sample application that you’ll build in this tutorial by clicking on the box below:

Download the sample code: Click here to get the code you’ll use to learn how to add menus, toolbars, and status bars to your GUI applications using Python and PyQt.

Building Python Menu Bars, Menus, and Toolbars in PyQt

A menu bar is a region of a GUI application’s main window that holds menus. Menus are pull-down lists of options that provide convenient access to your application’s options. For example, if you were creating a text editor, then you might have some of the following menus in your menu bar:

  • A File menu that provides some of the following menu options:
    • New for creating a new document
    • Open for opening an existing document
    • Open Recent for opening recent documents
    • Save for saving a document
    • Exit for exiting the application
  • An Edit menu that provides some of the following menu options:
    • Copy for copying some text
    • Paste for pasting some text
    • Cut for cutting some text
  • A Help menu that provides some of the following menu options:
    • Help Content for launching to user’s manual and help content
    • About for launching an About dialog

You can also add some of these options to a toolbar. A toolbar is a panel of buttons with meaningful icons that provide fast access to the most commonly used options in an application. In your text editor example, you could add options like New, Open, Save, Copy, and Paste to a toolbar.

Note: In this tutorial, you’ll develop a sample application that implements all the above menus and options. You can use this sample application as a starting point to create a text editor project.

In this section, you’ll learn the basics of how to add menu bars, menus, and toolbars to your GUI applications with Python and PyQt.

Before going any further, you’ll create a sample PyQt application that you’ll use throughout this tutorial. In each section, you’ll add new features and functionalities to this sample application. The application will be a main window–style application. This means that it’ll have a menu bar, a toolbar, a status bar, and a central widget.

Open your favorite code editor or IDE and create a Python file called sample_app.py. Then add the following code to it:

import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow

class Window(QMainWindow):
    """Main Window."""
    def __init__(self, parent=None):
        """Initializer."""
        super().__init__(parent)
        self.setWindowTitle("Python Menus & Toolbars")
        self.resize(400, 200)
        self.centralWidget = QLabel("Hello, World")
        self.centralWidget.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.setCentralWidget(self.centralWidget)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = Window()
    win.show()
    sys.exit(app.exec_())

Now sample_app.py contains all the code that you need for creating your sample PyQt application. In this case, Window inherits from QMainWindow. So, you’re building a main window–style application.

Note: Unfortunately, PyQt5’s official documentation has some incomplete sections. To work around this, you can check out either the PyQt4 documentation or the original Qt documentation.

In the class initializer .__init__(), you first call the parent class’s initializer using super(). Then you set the title of the window using .setWindowTitle() and resize the window using .resize().

Note: If you aren’t familiar with PyQt applications and how to create them, then you can check out Python and PyQt: Building a GUI Desktop Calculator.

The window’s central widget is a QLabel object that you’ll use to show messages in response to certain user actions. These messages will display at the center of the window. To do this, you call .setAlignment() on the QLabel object with a couple of alignment flags.

If you run the application from your command line, then you’ll see the following window on your screen:

PyQt Sample Application

That’s it! You’ve created a main window–style application with Python and PyQt. You’ll use this sample application for all the upcoming examples in this tutorial.

Creating Menu Bars

Read the full article at https://realpython.com/python-menus-toolbars/ »


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Python

via Planet Python https://ift.tt/1dar6IN

November 16, 2020 at 11:50AM

Python Morsels: How to Make a Function

Python Morsels: How to Make a Function

https://ift.tt/32LVk88



Related article:

Transcript:

How can you make your own function in Python?

Defining a function

Let’s make a function called greet that prints out "Hello world".

>>> def greet():
...     print("Hello world")
...

You can put as many statements as you like in a function, but we’ve chosen to just put one statement in this greet function.

When we call greet (by specifying the name of the function and open and close parentheses) Python will execute the statements inside that function:

>>> greet()
Hello world

If we pass an argument to the greet function, we’ll get an error:

>>> greet("Trey")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: greet() takes 0 positional arguments but 1 was given

We got an error because we passed an argument to greet but the greet function takes zero positional arguments.

Accepting arguments

To make a function that accepts arguments, you put the arguments in the parentheses when defining it.

Here we’ll modify our greet function to print out "Hello" and a name variable (instead of "world"):

>>> def greet(name):
...     print("Hello", name)
...

If we call this new greet function, we can pass a value to the name argument to print out that name:

>>> greet("Trey")
Hello Trey

So we use def to define a function, we type the name of the function we’re defining, and then we put parentheses.
Inside the parenthesis we put any arguments that our function accepts (if there’s more than one argument, they’re separated by commas).
That first line is always followed by a colon, which indicates the start of a block of code (meaning all the statements in the function are indented).

Positional vs keyword arguments

If we take the greet function and call it with Trey, this is a positional argument.
We can also pass in a keyword argument or a named argument.

We could pass the name in using a keyword argument like this:

>>> greet(name="Trey")
Hello Trey

Default argument values

If we don’t give any arguments to this function we’ll see an error because the greet function accepts a name argument, and it’s required:

>>> greet()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: greet() missing 1 required positional argument: 'name'

Function arguments are required by default in Python.
If you want to make optional arguments, you need to provide a default value.
We can specify a default value with an equals sign:

>>> def greet(name="world"):
...     print("Hello", name)
...

Note: that equals sign doesn’t have anything to do with keyword arguments.
When you call a function an equal sign specifies a keyword argument.
When you define a function, an equal sign defines a default value for an argument.

If we call this function with an argument it does the same thing as before:

>>> greet("Trey")
Hello Trey

But if we don’t supply an value for that argument, name will default to world.

>>> greet()
Hello world

Return values

Let’s take a function, product that accepts two arguments, numbers and start (which defaults to 1):

>>> def product(numbers, start=1):
...     total = start
...     for n in numbers:
...         total *= n
...     print(total)
...

This product function doesn’t really work the way it probably should.

When we call product with some numbers, 6 is printed out:

>>> total = product([2, 1, 3])
6

We would expect the variable total to be 6.
But it’s not 6: it is None!

>>> total
>>> print(total)
None

None is the default return value for all functions.

Arguments are the inputs to a function.
The return value is the output of a function.

Normally you’ll want your functions to have a return statement.

Let’s change the product function to return instead of calling print:

>>> def product(numbers, start=1):
...     total = start
...     for n in numbers:
...         total *= n
...     return total
...

Now that we’ve changed print to return, if we execute the same sort of code as before we’ll see nothing is printed out.

>>> total = product([2, 1, 3, 4])

But total is 24 now:

>>> total
24

When you call a function, it’s return value will be passed back to you, the caller of that function, and we can capture that into a variable or pass it off somewhere else.

Summary

To define a function in Python, you use the def keyword.
You put the name of the function, open and close parentheses, with any arguments inside those parentheses.
If any of the arguments are optional, you’ll need to give them default values.

Then you put a colon, to start defining the body of the function (a colon means you’ve got a block of code that’s going to be indented).
The statements you write will be executed when that function is called.

Importantly functions have inputs, which are their arguments and also an output, which is the return value of that function, which isn’t required, but most functions have a return value.

That’s how you make a function in Python!

Python

via Planet Python https://ift.tt/1dar6IN

November 16, 2020 at 02:54PM

Encrypting and signing data using private/public keys in PHP

Encrypting and signing data using private/public keys in PHP

https://ift.tt/35rI4Hr


For a project, I needed to make sure that a particular piece of data actually came from a specific source. There are already many packages that allow you to do this, but most are not fun or easy to use. That’s why we created a new package called spatie/crypto to do this.

Using spatie/crypto #

Using this package, it’s easy to generate a private and public key.

[$privateKey, $publicKey] = (new Spatie\Crypto\RsaKeyPair())->generate();

When passing paths, the generated keys will be passed to those paths.

(new KeyPair())->generate($pathToPrivateKey, $pathToPublicKey);

Using a private key, you can sign a message.

$privateKey = Spatie\Crypto\Rsa\PrivateKey::fromFile($pathToPrivateKey);
$signature = $privateKey->sign('my message'); 

The public key can use the signature to determine that the message was not tampered with.

$publicKey = Spatie\Crypto\Rsa\PublicKey::fromFile($pathToPublicKey);

$publicKey->verify('my message', $signature) 
$publicKey->verify('my modified message', $signature) 
$publicKey->verify('my message', 'invalid signature') 

Alternatives #

This package aims to be very lightweight and easy to use. If you need more features, consider using of one these alternatives:

A word on the usage of RSA #

At the time of writing, RSA is secure enough for the use case we’ve built this package for.

To know more about why RSA might not be good enough for you, read this post on public-key encryption at Paragonie.com

In closing #

Spatie/crypt can also encrypt and decrypt messages. To learn more, head over to the readme of spatie/crypto on GitHub.

On our company website, you’ll find a list of packages our team has created previously. If you would like to support us, consider picking up one of our paid products or sponsoring us on GitHub.

programming

via Laravel News Links https://ift.tt/2dvygAJ

November 15, 2020 at 08:49PM

Smart camera founder gets Wyze to car prowler and uses his own tech to catch criminal in action

Smart camera founder gets Wyze to car prowler and uses his own tech to catch criminal in action

https://ift.tt/38H9CL1

When Dave Crosby, one of the co-founders of Seattle-based Wyze Labs, was the victim of a robbery this summer, he turned to his own company’s technology for help in solving the crime. A new, outdoor security camera — unreleased to the public at the time — was mounted over his driveway and captured footage of a car prowler grabbing another of the cameras from Crosby’s vehicle.

Crosby, head of marketing for the 3-year-old smart home products maker, was testing the Wyze Cam Outdoor. He ended up as a main player in a YouTube video (above) that could serve as a testimonial for the new security device.

“I actually had grabbed those Outdoor Cams from the office and put them in my car because later that week I was shooting the actual promo video for the product,” Crosby told GeekWire, admitting that he mistakenly left his car unlocked. “Little did I know that a nice promo video would be created all on its own.”

When Crosby and co-workers discovered that the thief had posted the stolen camera for sale on Craigslist the next day, he set about chronicling it all for his popular YouTube channel, to document his efforts to catch a criminal. Crosby is no slouch on YouTube — he’s got 3.25 million subscribers who usually tune in to catch the father of three singing with his daughter.

He hit the ground running that day in August — and started filming himself — when he realized his car had been broken into and the footage was on his Wyze camera. Holding up a box for the Wyze Cam Outdoor, Crosby breathlessly said, “This is brand new. No one in the world has it. People are super excited to get this … it’s gonna be huge.”

Footage from Dave Crosby’s Wyze Cam Outdoor of a man entering Crosby’s vehicle at his home. (YouTube screen grab via The Crosbys)

Crosby moved about his home that morning, informing his wife Ashley of what happened and looping in his kids, Claire, 8, Carson, 6, and June, 2. A Wyze co-worker communicated with the thief on Craigslist, trying to arrange a spot to purchase the stolen camera for $50.

Crosby talked on the phone with police, trying to figure out the best way to have them involved as he made plans to be the one who would confront the thief. He said he definitely had some safety fears as he eventually set off the next day, with his family following in another vehicle, for a Fred Meyer parking lot in Renton, Wash. He was told to just dial 911 when he was in the area and police would arrive.

“I was surprised the police wanted me to just go make a deal with him,” Crosby told GeekWire, adding that once he was on the scene about to meet the seller, police arrived instantly before he could even talk to the guy.

“It was a fun adrenaline rush and I’m glad I got to be involved in catching him,” Crosby said.

The Wyze Cam Outdoor from Seattle-based Wyze Labs. (Wyze Photo)

The video captured Crosby filling out a police report in the back of his car, seated near his kids. Footage of the suspect is blurred as he talked to police. An officer returned the stolen camera to Crosby and remarked on Wyze’s technology in relation to it’s big Amazon-owned competitor.

“Good luck with the Wyze camera,” the officer said. “Gonna compete against Ring.”

“We are. We’re gonna take ’em down,” Crosby replied. The Wyze Cam Outdoor ended up selling out instantly when it was officially released and Crosby told GeekWire that it’s been a struggle to make them as fast as the startup can.

The value of the camera ended up not being enough to book the man into jail, and Crosby said he never followed up on the results of a supposed court date for the thief.

But his kids got a lesson in crime fighting and dad came away looking pretty cool.

“You could totally be a police,” his son said in the video.

And then the promo for Wyze cameras comes full circle as his daughter concluded, “And this is why we have WyzeCams, people.”

geeky

via GeekWire https://ift.tt/2pQ6rtD

November 12, 2020 at 05:48PM

Dear Farmers, miners, Red staters,

Dear Farmers, miners, Red staters,

https://ift.tt/3eSMmuH

This is a Biden supporter.

This is what they think of you.

Please stop shipping food into Blue cities.

Please stop shipping coal and oil into Blue cities.

Let them starve in the dark.

Thank you

 

guns

via https://gunfreezone.net

November 11, 2020 at 10:35PM

How to Generate PDF and Send Email in Laravel?

How to Generate PDF and Send Email in Laravel?

https://ift.tt/36HQxpF


Hi Artisan,

In this post, we will learn laravel generate pdf and send email. if you have question about laravel mail attachment pdf then i will give simple example with solution. In this article, we will implement a dompdf send email attachment laravel. we will help you to give example of generate pdf and send mail in laravel.

you can also generate pdf and send email in laravel 6, laravel 7 and laravel 8 application.

In this example, i will simply use dompdf to generate pdf file and send mail with pdf attachment. you just need to follow few step to create simple example of send mail with created pdf file in laravel app.

Let’s see bellow steps:

Step 1: Install Laravel

I am going to explain step by step from scratch so, we need to get fresh Laravel application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel blog

Step 2: Install dompdf Package

first of all we will install barryvdh/laravel-dompdf composer package by following composer command in your laravel 8 application.

composer require barryvdh/laravel-dompdf

After successfully install package, open config/app.php file and add service provider and alias.

config/app.php

'providers' => [

....

Barryvdh\DomPDF\ServiceProvider::class,

],

'aliases' => [

....

'PDF' => Barryvdh\DomPDF\Facade::class,

]

Step 3: Make Configuration

In first step, you have to add send mail configuration with mail driver, mail host, mail port, mail username, mail password so laravel 8 will use those sender details on email. So you can simply add as like following.

.env

MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

[email protected]

MAIL_PASSWORD=rrnnucvnqlbsl

MAIL_ENCRYPTION=tls

[email protected]

MAIL_FROM_NAME="${APP_NAME}"

Step 4: Add Route

In this is step we need to create routes for items listing. so open your “routes/web.php” file and add following route.

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\PDFController;

/*

|--------------------------------------------------------------------------

| Web Routes

|--------------------------------------------------------------------------

|

| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!

|

*/

Route::get('send-email-pdf', [PDFController::class, 'index']);

Step 5: Add Controller

Here,we require to create new controller PDFController that will manage index method of route. So let’s put bellow code.

app/Http/Controllers/PDFController.php

<?php

namespace App\Http\Controllers;

use PDF;

use Mail;

class PDFController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$data["email"] = "[email protected]";

$data["title"] = "From ItSolutionStuff.com";

$data["body"] = "This is Demo";

$pdf = PDF::loadView('emails.myTestMail', $data);

Mail::send('emails.myTestMail', $data, function($message)use($data, $pdf) {

$message->to($data["email"], $data["email"])

->subject($data["title"])

->attachData($pdf->output(), "text.pdf");

});

dd('Mail sent successfully');

}

}

Step 6: Create View File

In Last step, let’s create myTestMail.blade.php(resources/views/emails/myTestMail.blade.php) for layout of pdf file and put following code:

resources/views/emails/myTestMail.blade.php

<!DOCTYPE html>

<html>

<head>

<title>ItsolutionStuff.com</title>

</head>

<body>

<h1></h1>

<p></p>

<p>Thank you</p>

</body>

</html>

Now you can run and check example.

It will send you email, let’ see.

Run Project:

php artisan serve

Open Link:

localhost:8000/send-email-pdf

Output:

I hope it can help you…

programming

via Laravel News Links https://ift.tt/2dvygAJ

November 10, 2020 at 07:42PM