Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Laravel 7 Newsletter Tutorial with Example

Laravel 7 Newsletter Tutorial with Example

Posted on September 6, 2020December 15, 2022 By XpertPhp No Comments on Laravel 7 Newsletter Tutorial with Example

Today, We will explain to you the Laravel 7 Newsletter Tutorial with Example. here we are using the “Spatie/Laravel-newsletter” package to create a newsletter in laravel.

So you can follow the below steps for Newsletter Tutorial with example in laravel 7.

Overview

Step 1: Install Laravel 7

Step 2: Install Newsletter Package

Step 3: Sign Up and get API key in MailChimp

Step 4: Setup API Key

Step 5: Create Controller

Step 6: Create Route

Step 7: Create Blade Files

Step 8: Run Our Laravel Application

Laravel 7 Newsletter Tutorial with Example

Step 1: Install Laravel 7

We are going to install laravel 7, so first open the command prompt or terminal and go to xampp htdocs folder directory using the command prompt. after then run the below command.

PHP
1
composer create-project --prefer-dist laravel/laravel laravel7_newsletter

Step 2: Install Newsletter PackageIn this step, We will install an amazon s3 package using the below command.

1
composer require spatie/laravel-newsletter

Now, We will generate a configuration file for the newsletter using the following command.

1
php artisan vendor:publish --provider="Spatie\Newsletter\NewsletterServiceProvider"

Step 3: Sign Up and get API key in MailChimp
here in this step, you have to login or sign up on your Mailchimp account . after then you can find and get the API key in your Mailchimp account.

Step 4: Setup API Key
After the complete installation of the newsletter package. we have to set the API key and id configuration. now we will open the .env file and add the API key and id. See below changes in a .env file.

1
2
MAILCHIMP_APIKEY=Api Key
MAILCHIMP_LIST_ID=List Id

Step 5: Create Controller
Here below command help to create the controller.

1
php artisan make:controller NewsletterController

app/Http/NewsletterController.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
 
namespace App\Http\Controllers;
 
use Illuminate\Http\Request;
use Newsletter;
 
class NewsletterController extends Controller
{
    public function create()
    {
        return view('newsletter');
    }
 
    public function store(Request $request)
    {
        if ( ! Newsletter::isSubscribed($request->email) )
        {
            Newsletter::subscribePending($request->email);
            return redirect('newsletter')->with('success', 'Thanks For Subscribe');
        }
        return redirect('newsletter')->with('error', 'Sorry! You have already subscribed ');
            
    }
}
?>

Step 6: Create Route
Add the following route code in the “routes/web.php” file.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
/*
|--------------------------------------------------------------------------
| 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('newsletter','NewsletterController@create');
Route::post('newsletter','NewsletterController@store');
?>
See also  Laravel 7 Livewire File Upload From Scratch

Step 7: Create Blade Files

So finally, first we will open the newsletter.blade.php file and then paste the following code.
resources/views/newsletter.blade.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Laravel 7 Newsletter Tutorial with Example - XpertPhp</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12">
@if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
@if ($message = Session::get('error'))
<div class="alert alert-danger alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
</div>
</div>
  
        <form method="post" action="{{url('newsletter')}}">
        @csrf
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-2">
  <label for="Email">Email:</label>
  <input type="text" class="form-control" name="email">
</div>
</div>   
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
      </form>
</div>
</body>
</html>

Step 8: Run Our Laravel Application
We can start the server and run this example using the below command.

1
php artisan serve

Now we will run our example using the below Url in the browser.

1
http://127.0.0.1:8000/newsletter

Laravel Tags:laravel 7, laravel create newsletter, laravel newsletter, laravel newsletter app

Post navigation

Previous Post: Laravel 7 s3 File Upload Tutorial With Example
Next Post: Laravel 8 CRUD (Create Read Update Delete) Tutorial For Beginners

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Laravel 10 Ajax CRUD Example Tutorial
  • Laravel 10 CRUD Example Tutorial
  • How to disable button in React js
  • JavaScript Interview Questions and Answers

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com