Laravel Excel import-export

Laravel Excel import-export

https://ift.tt/2RbEUAi

Importing data from Excel sheet into our database and export data from the application into an Excel sheet are most often asked feature for a web application. These features enable us to perform batch import/export data by our web application. In Laravel, we can make excel import/export features easily with laravel maatwebsite/excel package. If you are looking for a step by step tutorial on how you can make excel import/export features in your application then it’s for you. In this post, I’ll show you a step by step guide for making excel import/export features in Laravel by using maatwebsite/excel laravel package with validation.

 

Steps for Laravel Excel Import-Export

  1. Install a new Laravel Framework instance
  2. Setup the database config & model.
  3. Install Laravel maatwebsite/excel package
  4. Make an Import class for import data.
  5. Make an Export class for export data
  6. Make a controller for handle excel data import or export

 

Install a new Laravel Framework instance

The first step, we need a fresh Laravel Framework instance. If you have already an application installed then skip this step. Let’s do that by composer command.

composer create-project laravel/laravel laravel-import-export

 

Setup the database config & model

In this step, we’ll set up our database configuration in the .env file.

DB_CONNECTION=mysql
 DB_HOST=127.0.0.1
 DB_PORT=3306
 DB_DATABASE=laravel-import-export
 DB_USERNAME=root
 DB_PASSWORD=

 

Now make a model. Here we’ll make a contact model for our contacts table. Our contacts table contains id, name, phone, email fields.

<?php namespace App;
 
 use Illuminate\Database\Eloquent\Model;
 
 class Contact extends Model {
 public $timestamps = false;
 protected $fillable = ['name', 'phone', 'email'];
 } 

 

Install Laravel maatwebsite/excel package

Now install the Laravel maatwebsite/excel version 3.1 package via composer command.

composer require maatwebsite/excel

This package has auto-discovery features so you don’t need to add the service provider manually.

 

Make an Import class for import data.

Now we have to make an Import class for importing data into our database from Excel sheet via our contact model. The maatwebsite/excel package provides useful command to make the class easily. Let’s do that.

php artisan make:import ContactsImport --model=Contact

with this command, a Contact import class will create in the app/Imports directory.

<?php
 
 namespace App\Imports;
 
 use App\Contact;
 use Illuminate\Support\Facades\Hash;
 use Maatwebsite\Excel\Concerns\ToModel;
 
 class ContactsImport implements ToModel
 {
 /**
 * @param array $row
 *
 * @return Contact|null
 */
 public function model(array $row)
 {
 return new Contact([
 'name' => $row[0],
 'phone' => $row[1], 
 'email' => $row[2]
 ]);
 }
 }

 

Make an Export class for export data

For export data from our database to Excel sheet, we need to make an Export class via command line.

php artisan make:export ContactsExport --model=Contact

By this command, a class file will create in app/Exports directory.

<?php
 
 namespace App\Exports;
 
 use App\Contact;
 use Maatwebsite\Excel\Concerns\FromCollection;
 
 class ContactsExport implements FromCollection
 {
 public function collection()
 {
 return Contact::all();
 }
 }

 

Make a controller for handle excel data import or export

Now the final part where we’ll handle how we’ll export or import data and what will be the logic goes to. Let’s make a controller by artisan make command.

php artisan make:controller ContactController

 

Handle Excel data import

To import data from excel sheet, make an import method inside the contact controller. In this import method, we’ll validate our request file and code for import the excel sheet data.

<?php
 
 use App\Imports\ContactsImport;
 use Maatwebsite\Excel\Facades\Excel;
 use App\Http\Controllers\Controller;
 
 class ContactsController extends Controller 
 {
 public function import(Request $request) 
 {
 $this->validate($request, [
 'file' => 'required|file|mimes:xls,xlsx'
 ]);
 
 $file = $request->file('file');
 Excel::import(new ContactsImport, $file);
 return redirect()->back()->with('success', 'All data successfully imported!');
 }
 }

 

Handle Excel data export

With the data export feature, we can export our table data into an excel sheet very easily. For that, make an export method inside the contact controller and do code for model data export into an excel sheet.

<?php
 
 namespace App\Http\Controllers;
 
 use App\Exports\ContactsExport;
 use Maatwebsite\Excel\Facades\Excel;
 
 class ContactController extends Controller 
 {
 
 public function export() 
 {
 return Excel::download(new ContactsExport, 'contacts.xlsx');
 }
 }

 

Hopefully, this step by step tutorial post will help you to add excel data import/export features in your laravel application. If this post helpful to you then please share with others so that they get helped.

programming

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

April 3, 2020 at 08:00AM

Fisher Clutch Space Pen

Fisher Clutch Space Pen

https://ift.tt/3aINu1e

Fisher Clutch Space Pen

 | Buy

Made from black anodized aluminum, Fisher’s Clutch Space Pen has a bold and substantial look. Its hexagonal barrel provides a confident grip, and won’t roll off your desk. With its pressurized ink cartridge, it has no trouble writing upside-down, or in extreme temperatures, and can even write underwater.

fun

via The Awesomer https://theawesomer.com

April 2, 2020 at 10:31AM

Laravel send e-mail A to Z

Laravel send e-mail A to Z

https://ift.tt/2w6CjjC

Sending e-mail is an important part of our application. Laravel made it easy with simple e-mail sending API. You can send email from STMP, Gmail, Webmail, Mailgun, Amazon SES, SendGrid, Mailtrap and etc with the same API. If you are looking for sending an email in Laravel framework via SMTP, Gmail, Mailgun, Amazon SES, Webmail, SendGrid or any email service then this post will help you by providing the complete guide on how to send an e-mail via Laravel 6. By following this post you can do exactly the same thing in Laravel 5 or Laravel 6. By completing this post, We’ll learn below.

  • How to send test e-mail for confirming all are ok via MailTrap.
  • How to send an email with Webmail SMTP in Laravel
  • How to send an email with Gmail in Laravel
  • How to send an email with SendGrid SMTP in Laravel
  • Laravel Send Mail without a view
  • Recommendations

 

Step 01: E-mail View

We have to make an e-mail template for sending the email content to our recipients. For that, Here I’m creating a simple HTML email template in resources/views/emails/template.blade.php with the content below.

<div>
 <h3>Hi, </h3>
 <p><p> 
 </div>

Look, In this template, we will pass $name and $msgBody variable data and send it to our recipients. With this simple e-mail template, I’ll show you how to send an e-mail via Mailtrap, SMTP, Gmail, Webmail etc.

Important Note Do not pass any variable name with message. If you do then it’ll conflict and you will get an exception.

 

Step 02: Define Route

We need to define a route in web.php file for sending an e-mail. Let’s do that.

Route::get('/send-mail','HomeController@sendMail');

 

Step 03: Controller Code

Now we need to code in sendMail function for sending our email.

// HomeController.php
 
 use Illuminate\Support\Facades\Mail;
 
 public function sendMail()
 {
 $data = [
 'name'=>'Jhon Smith',
 'msgBody'=>'Welcome to Laravel Article'
 ];
 
 Mail::send('emails.template',$data,function($mail){
 $mail->from('info@example.com');
 $mail->to('jhon@example.com');
 $mail->subject('Welcome E-mail');
 });
 
 return 'Successfully send';
 }

 

First testing E-mail with MailTrap

Here first we’ll send e-mails via Test mail sending sandbox service name Mailtrap. Mailtrap is really awesome for testing email before sending with our actual email sending credentials. We are doing this for confirming that our email is sending correctly with the correct content. Sometimes from Webmail, Gmail STMP are not work as we expected for some miss-configuration. If we succeed with MailTrap then we can ensure that our sending process ok we have to focus on other things.

  • Login to Mailtrap account and goto Demo Inbox.
  • From the integrations dropdown, select laravel
  • Now copy the env configuration and paste into your env file

  mailtrap-integration.png

Now, start the server php artisan serve and hit URL http://localhost:8000/send-mail

test-email-snap.png

 

2. How to send an e-mail with Webmail SMTP in Laravel?

– Do login into cPanel and create a Webmail.

– Collect mail client configuration for your webmail.

– Update configuration in your project env file.

MAIL_DRIVER=smtp
 MAIL_HOST=mail.example.com
 MAIL_PORT=465
 MAIL_USERNAME=info@example.com
 MAIL_PASSWORD=your_webmail_password
 MAIL_FROM_ADDRESS=from@example.com
 MAIL_FROM_NAME=Example

and finally, do exactly the same as step 1, 2, 3

Now, start the server php artisan serve and hit URL http://localhost:8000/send-mail

 

3. How to send an email with Gmail in Laravel?

Important: Sending e-mail using Gmail, first you need to enable less secure apps settings from your Google Account. If you do not enable this option then you will not able to send email using Gmail from your Laravel application.

– After enabling the less secure apps option, update the env file.

MAIL_DRIVER=smtp
 MAIL_HOST=smtp.gmail.com
 MAIL_PORT=587
 MAIL_USERNAME=your_gmail_address
 MAIL_PASSWORD=your_gmail_password
 MAIL_ENCRYPTION=tls

and finally, do exactly the same described in step 1, 2, 3

Now, start the server php artisan serve and hit URL http://localhost:8000/send-mail

 

4. How to send an email with SendGrid SMTP in Laravel?

Login to your SendGrid account.

Do sender authentication from Settings > Sender Authentication

Goto Settings > API keys and Create an API key by enabling Restricted Access ( Only send email )

sendgrid-api-key.png

 

Now update the env file with configuration.

MAIL_DRIVER=smtp
 MAIL_HOST=smtp.sendgrid.net
 MAIL_PORT=587
 MAIL_USERNAME=apikey
 MAIL_PASSWORD=your_api_secret
 MAIL_ENCRYPTION=tls

N.B: Keep exactly MAIL_USERNAME=apikey

and finally, do exactly the same described in step 1, 2, 3

Now, start the server php artisan serve and hit URL http://localhost:8000/send-mail

 

5. Laravel Send Mail without a view

For sending email without view in Laravel, you have to use the raw method of Laravel Mail facade. Just follow the steps below.

– Simply define a route.

Route::get('/send-mail','HomeController@sendMail');

– Setup mail credentials in env file from one of these ( Webmail, Gmail, SendGrid, Mailtrap etc)

– Do code in the sendMail method

// HomeController.php
 
 use Illuminate\Support\Facades\Mail;
 
 public function sendMail()
 {
 
 Mail::raw('Hi, welcome to laravelarticle.com!', function ($mail) {
 $mail->from('info@example.com');
 $mail->to('jhon@example.com');
 $mail->subject('Welcome E-mail');
 });
 
 return 'Successfully send';
 }

 

Recommendations

Use your credentials in the env file only local development. On the production side, do not put credentials in the env file, keep your credentials in the config/mail.php file.

 

Hope this post will help you to send email in Laravel framework with confidently. If this post helps you to learn how to send email in Laravel framework then please share this post with others.

programming

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

April 2, 2020 at 08:18AM

VIDEO: High School Wrestling Champ Slams, Pins New Mexico Kidnapper

VIDEO: High School Wrestling Champ Slams, Pins New Mexico Kidnapper

https://ift.tt/3aLhfy4

A 16-year-old high school wrestler that just won a district title; well, that’s already a big man on campus. When that same teen saves the lives of three little kids, overpowering a grown man to do so? Now he just became legend. Such is the latest podium for Canaan Bower, who took on and pinned a kidnapper in Las Cruces, N.M. recently. The athlete slammed the thug to the ground, then held him until police arrived.

Coronavirus Home Defense, Home Defense Checklist, COVID-19 checklist

RELATED STORY

5 Things to Keep in Mind for Your Coronavirus Home Defense Checklist

Canaan Bower Pins  New Mexico Kidnapper

It turned out a very good thing the wrestler appeared on the scene. The attacker, 22-year-old Daniel Arroyo Beltran, allegedly assaulted a woman and her three young children. Closed circuit security footage captured the man repeatedly attempt to kidnap the three kids. When a bystander attempted to hold the door, keeping Beltran out of a convenience store where the woman and kids took refuge, Beltran forced his way in and attacked. He punched the man several times, with blood spurting to the floor.

That’s when the champion wrestler, pumping gas outside, saw the commotion and leapt into action. He ran into the store, confronted Beltran, and put his wrestling skills to work.

“So my son – who just won the wrestling district championship weeks ago – just came up behind this guy and body-slammed him and got him in a chokehold and waited for the police to show up,” Troy Bower, Canaan’s father, told lcsun-news.com.

The Dona Ana County Sheriff’s Office thanked Bower for “stepping up to save the lives of two children and potentially many others.”

Even UFC President Dan White took notice of the wrestling champ and his bravery. Noting the current coronavirus and social distancing requirements, White said he’d love to meet Bower, who he called “AWESOME!!!,” in the future.

For a wrestler, at any age, it doesn’t get much better than that.

The post VIDEO: High School Wrestling Champ Slams, Pins New Mexico Kidnapper appeared first on Personal Defense World.

guns

via Personal Defense World https://ift.tt/2Arq2GB

April 1, 2020 at 06:08AM

Introducing Metabase, a Simple and Powerful Analytics Tool

Introducing Metabase, a Simple and Powerful Analytics Tool

https://ift.tt/2X0JAfP

metabase

metabaseRecently I was looking for some simple way to analyze and create graphs from data stored in MySQL tables. I know Grafana can also plot graphs from MySQL tables, but somehow it felt like overkill and you are not using the traditional SQL syntax there. So I was searching for another solution, and it actually took me a while to find it. I might have used the wrong keywords when searching, or the SEO is not the best for this site/project, but in the end, I found Metabase.

In this blog post, I would like to highlight this open source project because I found it very simple and it does the job perfectly for what I wanted it for.

What Is Metabase?

I would describe Metabase as a tool that can provide you a graphical interface to create business intelligence and analytics graphs in minutes. It does not require any previous SQL knowledge, and it has a nice interface where you can simply make analytics with just a few clicks.

Is It Only for MySQL?

It supports a lot of backend databases:

  • MySQL
  • Postgres
  • Druid
  • SQL Server
  • Redshift
  • MongoDB
  • Google BigQuery
  • SQLite
  • H2
  • Oracle
  • Vertica
  • Presto
  • Snowflake
  • SparkSQL

Installation

It is very simple; you can just call the JAR file or run a docker container and it is done. You can run on AWS Elastic Beanstalk, or on Heroku, or even on Kubernetes.

After installation, you only have to add your datasource and you are good to go.

Creating a Graph

Using a test IMDB database, we simply graph how many movies were created per year. It takes only a few seconds and a few clicks. Of course, we can write a query by ourselves as well, and it is able to plot the result without any problems.

It Has a Lot of Features

Metabase has a lot of features and settings, but here I will just mention a few:

  • Work with large databases and configure when and how they should scan the data.
  • It can handle multiple users.
  • It can handle permissions.
  • It works with Slack and you can create questions/graphs from Slack.
  • You can create dashboards where you can add your graphs.
  • You can share dashboards and graphs.
  • Activity log
  • Alerts

Conclusion

If you are looking for a very simple data visualization or business analytics tool, I would definitely recommend taking a look at Metabase. Please let us know what you think if you are already using it!

technology

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

April 1, 2020 at 03:25PM

Take a Virtual Trip to Disney World

Take a Virtual Trip to Disney World

https://ift.tt/2R2qLVL

If, a few weeks ago, you’d told your kids that you were all going to TAKE A TRIP TO DISNEY WORLD and then added the caveat, “from the comfort of our own home,” chances are there would have been a mutiny. But, as we all know, things have changed. Standards have been lowered. Now, riding Splash Mountain from the living room couch might not seem like such a bad idea.

We’ve written before about how you can use YouTube videos to prepare kids for potentially anxiety-producing events—such as riding a rollercoaster. But you can also use those same videos to make your way across Magic Kingdom without ever needing to take a step, complain about the length of a line or manage a meltdown.

As Christina Marfice reminds us on Scary Mommy, there are entire channels on YouTube that provide videos taken by riders on Disney parks attractions:

That means anyone with a device and an internet connection can relive the magic. And it’s even better if you have a virtual reality headset or smartphone mount. Then, the videos become fully immersive experiences, basically like being back at Disneyland before the world almost totally shut down.

Is it the same as actually being on the ride? As someone who has been to Disney World a handful of times, I can categorically state that it is not. But are some of the ride videos surprisingly satisfying? They are—especially now, when the thought of being in such a germy place, among tight crowds of people, seems like such a quaint concept from a more innocent era.

So where to start? You don’t have to plan your day around your FastPass times and you can bounce back and forth across the park in mere seconds. Since I’m the one writing this and Pirates of the Caribbean is my favorite ride, let’s start there.

All those people! Touching all the surfaces! And then touching their faces with abandon! 2019 really was a simpler time. That was fun, but I’ve got Splash Mountain on the brain; let’s go there next.

If your kids like a bit of a thrill (but not too much!), the Barnstormer roller coaster is a good option. I chose this particular video because it’s a gloomy, rainy day at Disney, the park is basically deserted and it just feels … right:

If you prefer more people and more sunshine, try the Slinky Dog Dash roller coaster. Yes, I know, this ride is in an entirely different park (Hollywood Studios). Does it matter? No, it does not—there are no rules here!

Is it time for the Frozen ride, yet? Yes, I thought so. Come on, let’s head to Epcot; it’s right over here:

Okay, I wasn’t even going to click on the video for the Avatar ride (Animal Kingdom) because it’s such an incredible in-person experience that I was sure I would be disappointed. I was not. If I can’t be physically on this ride right now, at least I’ve got this:

If you haven’t had enough, the LMG Vids YouTube Channel has playlists of rides from a variety of theme parks, including all the Disney parks in Orlando and California, Legoland California, Knott’s Berry Farm, and the Tokyo and Hong Kong Disneylands.


Meet the smartest parents on Earth! Join our parenting Facebook group.

geeky,Tech,Database

via Lifehacker https://lifehacker.com

April 1, 2020 at 02:03PM

The Best String Trimmers

The Best String Trimmers

https://ift.tt/2p0nDLT

The Best String Trimmers

After using 10 string trimmers to level 12,598 square feet of an overgrown field and trimming over 6,000 linear feet along walls and fences, we’re convinced the best string trimmer (also known as a weed wacker or a weed eater) is the Ego ST1502-SF Power+ 15" String Trimmer.

technology

via Wirecutter: Reviews for the Real World https://ift.tt/2gcK1uO

March 31, 2020 at 04:22PM

5 Powerful Tools for Digital Marketing Success

5 Powerful Tools for Digital Marketing Success

https://ift.tt/2UTwaj1

Photo by Lukas Blazek on Unsplash

Today, the role of digital in your overall marketing strategy is unquestionable. Moreover, the rapid growth of digital marketing has brought with it a range of methods and solutions for making the most of what the Internet has to offer. From SEO to PPC to social, video, email, and beyond, there are more options for digital marketing now than ever before. However, utilizing them for real digital marketing success is becoming increasingly complex.

RELATED ARTICLE: DON’T LOSE YOUR STARTUP TO CHAOS

Digital Marketing Success Will Keep You Ahead of the Pack

Staying ahead of the competition is no longer something you can do alone. There’s simply too much work to do. For example, your success with digital marketing will take planning, implementing, analyzing, and improving the elements that make up your digital strategy. Therefore, to maintain a steady pace, consider utilizing these five powerful tools for digital marketing success.

Proof

The aptly named Proof uses the power of social proof messaging to boost your website’s conversion rates.

For example, Proof will send notifications, reviews, and videos to targeted customers after they leave your site. Proof works to enhance the perception of your brand. Their experts will also optimize your website design for better conversion rates. So give them a chance to help you enjoy more digital marketing success.

HubSpot

HubSpot is designed to serve as the central platform for managing your digital marketing efforts. Its tools can lead to more success online.

It offers numerous free tools for new businesses to get started with. For example, you’ll find web forms and live chat software for capturing leads. You can also make use of their basic analytics and customer relations management features without spending any money. Just imagine! More digital marketing success, for free.

However, if you want even more digital marketing success, you can have it. For example, expect some impressive marketing automation features when moving into the paid tiers. This includes integration with other software in the category. It will also help you develop a powerful tool for growing traffic, converting leads, and increasing ROI on marketing campaigns.

Plus, you’ll get help with improving close rates for deals with their effective sales tools.

SendGrid

When it comes to digital success with email marketing, a dedicated tool for creating, executing, and managing campaigns is a must. SendGrid is one of them. Its multiple features include promotional emails, automation, and design tools.

That said, its popularization has spawned a number of SendGrid alternatives that are worth looking into. This is because some of these alternatives have lower pricing tiers or longer lists of features.

So be sure to check them out before settling on a specific solution. Any one of them could lead you into more digital marketing success.

Survey Anyplace

Are you looking to improve user experience? Do you want to design a better product or learn more about your market? Or are you simply interested in having more digital marketing success overall?

Customer surveys are a great way to achieve any of these objectives. This is because Survey Anyplace aims to reduce the chances of participants abandoning your survey. They do this by helping you build simple, well-designed forms that are mobile compatible.

Yoast

This popular WordPress plugin is a handy tool for optimizing your website content search engines. Regularly updated to reflect the latest algorithms, Yoast helps you identify the best content, focus keywords, and internal links.

These optimizations will improve your rankings and give you more digital marketing success. Yoast also evaluates the readability of your pages for an additional boost.

The Right Tools Will Bring Greater Digital Marketing Success

You can build a comprehensive and successful digital marketing strategy. However, you cannot do it without the right tools.

But whether you’re looking to reduce your team’s workload with automation, gain greater insights into the effectiveness of your endeavors, or explore new avenues for marketing your business online, there’s a digital tool that can help you make it happen.

The post 5 Powerful Tools for Digital Marketing Success appeared first on Business Opportunities.

business

via Business Opportunities Weblog https://ift.tt/2CJxLjg

March 31, 2020 at 11:09AM

Apple acquires Dark Sky weather app, and that’s bad news for Android users

Apple acquires Dark Sky weather app, and that’s bad news for Android users

https://ift.tt/2WYoMG3

  • An example of Dark Sky’s maps from the desktop Web version.

  • Here’s a precipitation heatmap from the iOS version.

  • This is the main view in the iOS app.

    Dark Sky

  • And here’s the multi-day forecast in the app.

    Dark Sky

  • This push notification went out to iOS users today.

Popular weather app and data-collection service Dark Sky has been acquired by Apple for an undisclosed sum, a blog post from the Dark Sky team announced. The post claims that Dark Sky will now “reach far more people, with far more impact, than we ever could alone.”

The iOS app will not see any changes “at this time,” and it will continue to be listed on the App Store. Android and Wear OS are a different story, though. The Android app will no longer be available for download, and “service to existing users and subscribers will continue until July 1, 2020, at which point the app will be shut down.” Active subscribers will get a refund.

As for the website, which is also popular:

Weather forecasts, maps, and embeds will continue until July 1, 2020. The website will remain active beyond that time in support of API and iOS App customers.

A lot seems to be up in the air about where this will go in the long term, though. Dark Sky is notable in part for its big data-driven Dark Sky Forecast API, which provides customers with hyper-local weather data for use in their own apps or services. That API will no longer accept new signups, though “service for existing customers is not changing today.” The API will function for existing customers through the end of 2021.

That API and the related data operation may be the main reason Apple was interested in Dark Sky; the service is known for providing smart notifications and highly localized data about precipitation, among other things, in much more detail than Apple’s own Weather app.

The blog post also notes that Dark Sky will now be subject to Apple’s privacy policy, and the app’s developer is already listed as “Apple” in the App Store.

Listing image by Dark Sky

geeky

via Ars Technica https://arstechnica.com

March 31, 2020 at 03:37PM