SlideShare a Scribd company logo
Task Scheduling
in Laravel 8
Tutorial
www.bacancytechnology.com
In this tutorial, we will learn how to
implement Task Scheduling in Laravel 8. We
will build a demo app that will e-mail the
weekly report of an employee’s task details
to their manager.
Task Scheduling in Laravel 8 Tutorial:
What are we building?
Create and Navigate to Laravel Project
Create Controller: TaskAddController
User Interface: Create Form
Add Route
Create Model and Migration
Update Mail Class
Create Artisan command
Schedule command
Conclusion
CONTENTS
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Task
Scheduling in
Laravel 8
Tutorial:
What are we
building?
Let’s clarify what we are going to build in
the demo.
The user interface will have a form that will
take details (employee with tasks) and the
manager’s email ID (to send a weekly
report).
After submitting the form, the report will
automatically be generated and mailed to
the manager at the end of the week.
Create and
Navigate to
Laravel
Project
Let’s start a new Laravel project, for that
run the below command in your cmd,
composer create-project laravel/laravel
task-scheduling-demo
cd task-scheduling-demo
Create
Controller:
TaskAddCont-
roller
After creating the database and adding mail
configurations to the .env file, use the
following command to create a controller.
php artisan make:controller
TaskAddController
User
Interface:
Create Form
Moving towards the UI part. We need to
create a form that will take employee and
task details with the manager’s email ID
(the report will be sent).
Open welcome.blade.php and add below
code in your tag.
<div class="container">
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
<form method="post" action="
{{route('addData')}}">
@csrf
<h2>Employee Details</h2><br>
<div class="form-group">
<label>Id</label>
<input type="number" name="e_id"
class="form-control" placeholder="Enter
Employee_Id">
</div>
<div class="form-group">
<label>Name</label>
<input type="text" name="e_name"
class="form-control" placeholder="Enter
Your Name">
</div>
<div class="form-group">
<label>Email address</label>
<input type="email" name="e_email"
class="form-control" placeholder="Enter
Your Email">
</div>
<div class="form-group">
<h2>Task Details</h2><br>
<div class="form-group">
<label>Monday</label>
<input type="text" name="t_mon"
class="form-control" placeholder="Task
done by Monday">
</div>
<div class="form-group">
<label>Tuesday</label>
<input type="text" name="t_tue"
class="form-control" placeholder="Task
done by Tuesday">
</div>
<div class="form-group">
<label>Wednesday</label>
<input type="text" name="t_wed"
class="form-control" placeholder="Task
done by Wednesday">
</div>
<div class="form-group">
<label>Thursday</label>
<input type="text" name="t_thu"
class="form-control" placeholder="Task
done by Thursday">
</div>
<div class="form-group">
<label>Friday</label>
<input type="text" name="t_fri"
class="form-control" placeholder="Task
done by Friday">
</div>
</div>
<div class="form-group"></div>
<button type="submit" class="btn btn-
primary">Submit</button>
</form>
</div>
The UI will look something like this-
Add Route
For adding route, use below code in
web.php file
use
AppHttpControllersTaskAddController;
Route::post('/addData',
[TaskAddController::class,'addTask'])-
&gt;name('addData');
Create Model
and Migration
In this step we will create one model and
migration file to save the report of the
employee. For that use the below command.
php artisan make:model AddTask -m
After creating the migration file, add table
structure in it.
<?php
use
IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
class CreateAddTasksTable extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('add_tasks', function
(Blueprint $table) {
$table->id();
$table->bigInteger('e_id');
$table->string('e_name');
$table->string('e_email');
$table->string('manager_email');
$table->string('t_mon');
$table->string('t_tue');
$table->string('t_wed');
$table->string('t_thu');
$table->string('t_fri');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('add_tasks');
}
}
Update Controller
To update TaskAddController add below
code:
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppModelsAddTask;
class TaskAddController extends Controller
{
public function addTask(Request
$request)
{
$data = $request->all();
$task = new AddTask();
$task->e_id = $data['e_id'];
$task->e_name = $data['e_name'];
$task->e_email = $data['e_email'];
$task->manager_email =
$data['manager_email'];
$task->t_mon = $data['t_mon'];
$task->t_tue = $data['t_tue'];
$task->t_wed = $data['t_wed'];
$task->t_thu = $data['t_thu'];
$task->t_fri = $data['t_fri'];
$task->save();
return back()->with('status','Data added
successfully');
}
}
Create Mail
Class with
Markdown
Now we create a mail class with a
markdown. For that apply the below
command.
php artisan make:mail WeeklyReport --
markdown=emails.weeklyReport
Update Mail
Class
After creating, update the mail class.
Open AppMailWeeklyReport.php
<?php
namespace AppMail;
use IlluminateBusQueueable;
use
IlluminateContractsQueueShouldQueue;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
class WeeklyReport extends Mailable
{
use Queueable, SerializesModels;
public $body;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($body)
{
$this->body = $body;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this-
>markdown('email.weeklyReport');
}
}
For creating mail structure, open
viewsemailweeklyReport.blade.php
Hello..
This mail contains Weekly report of your
Team.
<style>
table, th, td {
border: 1px solid black;
}
table {
width: 100%;
border-collapse: collapse;
}
</style>
<table >
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{$body->e_id}}</td>
<td>{{$body->e_name}}</td>
<td>{{$body->e_email}}</td>
<td>{{$body->t_mon}}</td>
<td>{{$body->t_tue}}</td>
<td>{{$body->t_wed}}</td>
<td>{{$body->t_thu}}</td>
<td>{{$body->t_fri}}</td>
</tr>
</tbody>
</table>
Create
Artisan
command
For sending the weekly report we need to
create an artisan command .
Use the following the command for the
same
php artisan make:command
sendWeeklyReport
Now go to the
AppConsoleCommandssendWeeklyRepo
rt.php and add the below code.
The handle() method of this class gets all the
data from the database; for each employee
report will be generated and sent to the
email ID provided in the form, here
manager’s email ID.
<?php
namespace AppConsoleCommands;
use IlluminateConsoleCommand;
use AppModelsAddTask;
use AppMailWeeklyReport;
use Mail;
class sendWeeklyReport extends Command
{
/**
* The name and signature of the console
command.
*
* @var string
*/
protected $signature =
'weekly:mail_report';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Weekly report
send to Manager';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$emp = AddTask::all();
foreach($emp as $empl)
{
$email = $empl->manager_email;
$body = $empl;
Mail::to($email)->send(new
WeeklyReport($body));
$this->info('Weekly report has been sent
successfully');
}
}
}
Schedule
command
Open AppConsoleKernal.php and update
the schedule method of that class to add a
scheduler.
protected function schedule(Schedule
$schedule)
{
$schedule-
>command('weekly:mail_report')-
>weekly();
}
To run the scheduler locally, use the
following command
php artisan schedule:work
You can check the Laravel official
documentation for exploring more about
Task scheduling in Laravel 8.
Open terminal and run crontab -e.
So far, we have defined our scheduled tasks;
now, let’s see how we can run them on the
server. The artisan command schedule:run
evaluates all the scheduled tasks and
determines whether they need to be run on
the server’s current time.
To set up crontab, use the following
instructions-
Setup Crontab
Add the below line to the file.
Save the file.
* * * * * cd /path-to-your-project && php
artisan schedule:run >> /dev/null 2>&1
Run the project
php artisan serve
Fill the required details as shown below-
On submitting the form, the email will be
sent.
Conclusion
So, this was about how to implement Task
scheduling in Laravel 8. For more such
tutorials, visit Laravel Tutorials Page and
clone the github repository to play around
with the code.
If you have any queries or requirements for
your Laravel project, feel free to connect
with Bacancy to hire Laravel developers.
Thank You
www.bacancytechnology.com

More Related Content

What's hot

Installing php 7.4 Nginx Laravel 7.x on Centos 8
Installing php 7.4 Nginx Laravel 7.x on Centos 8Installing php 7.4 Nginx Laravel 7.x on Centos 8
Installing php 7.4 Nginx Laravel 7.x on Centos 8
Raja Rozali Raja Hasan
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Joe Ferguson
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
Viral Solani
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
Raf Kewl
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
Christopher Pecoraro
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
Bukhori Aqid
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
Vikas Chauhan
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
Toufiq Mahmud
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel framework
Ahmad Fatoni
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
Jonathan Goode
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentials
Pramod Kadam
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Lorvent56
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
Sudip Simkhada
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
Christopher Pecoraro
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
Abuzer Firdousi
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
Singapore PHP User Group
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should know
Povilas Korop
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
Bart Van Den Brande
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
Blake Newman
 

What's hot (20)

Installing php 7.4 Nginx Laravel 7.x on Centos 8
Installing php 7.4 Nginx Laravel 7.x on Centos 8Installing php 7.4 Nginx Laravel 7.x on Centos 8
Installing php 7.4 Nginx Laravel 7.x on Centos 8
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel framework
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentials
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should know
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
 

Similar to Task scheduling in laravel 8 tutorial

Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_cs
Alfa Gama Omega
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
Katy Slemon
 
Test
TestTest
Devise and Rails
Devise and RailsDevise and Rails
Devise and Rails
William Leeper
 
Asp.net tips
Asp.net tipsAsp.net tips
Asp.net tips
actacademy
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
Akhil Mittal
 
ASP.NET Identity
ASP.NET IdentityASP.NET Identity
ASP.NET Identity
Suzanne Simmons
 
Ways to Set Focus on an Input Field After Rendering in React.pptx
Ways to Set Focus on an Input Field After Rendering in React.pptxWays to Set Focus on an Input Field After Rendering in React.pptx
Ways to Set Focus on an Input Field After Rendering in React.pptx
BOSC Tech Labs
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
Sapna Upreti
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScript
Katy Slemon
 
METEOR 101
METEOR 101METEOR 101
METEOR 101
Tin Aung Lin
 
A To-do Web App on Google App Engine
A To-do Web App on Google App EngineA To-do Web App on Google App Engine
A To-do Web App on Google App Engine
Michael Parker
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...
naseeb20
 
Jsf intro
Jsf introJsf intro
Jsf intro
vantinhkhuc
 
Well
WellWell
Well
breccan
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
dharisk
 
ReactJS.pptx
ReactJS.pptxReactJS.pptx
ReactJS.pptx
SamyakShetty2
 
Mvc - Titanium
Mvc - TitaniumMvc - Titanium
Mvc - Titanium
Prawesh Shrestha
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
Biztech Consulting & Solutions
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Nicolás Bouhid
 

Similar to Task scheduling in laravel 8 tutorial (20)

Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_cs
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
Test
TestTest
Test
 
Devise and Rails
Devise and RailsDevise and Rails
Devise and Rails
 
Asp.net tips
Asp.net tipsAsp.net tips
Asp.net tips
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
ASP.NET Identity
ASP.NET IdentityASP.NET Identity
ASP.NET Identity
 
Ways to Set Focus on an Input Field After Rendering in React.pptx
Ways to Set Focus on an Input Field After Rendering in React.pptxWays to Set Focus on an Input Field After Rendering in React.pptx
Ways to Set Focus on an Input Field After Rendering in React.pptx
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScript
 
METEOR 101
METEOR 101METEOR 101
METEOR 101
 
A To-do Web App on Google App Engine
A To-do Web App on Google App EngineA To-do Web App on Google App Engine
A To-do Web App on Google App Engine
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Well
WellWell
Well
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
 
ReactJS.pptx
ReactJS.pptxReactJS.pptx
ReactJS.pptx
 
Mvc - Titanium
Mvc - TitaniumMvc - Titanium
Mvc - Titanium
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
 

More from Katy Slemon

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Katy Slemon
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
Katy Slemon
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
Katy Slemon
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
Katy Slemon
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
Katy Slemon
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
Katy Slemon
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
Katy Slemon
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
Katy Slemon
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Katy Slemon
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
Katy Slemon
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
Katy Slemon
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
Katy Slemon
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
Katy Slemon
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
Katy Slemon
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Katy Slemon
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Katy Slemon
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
Katy Slemon
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
Katy Slemon
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Katy Slemon
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
Katy Slemon
 

More from Katy Slemon (20)

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
 

Recently uploaded

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 

Recently uploaded (20)

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 

Task scheduling in laravel 8 tutorial

  • 1. Task Scheduling in Laravel 8 Tutorial www.bacancytechnology.com
  • 2. In this tutorial, we will learn how to implement Task Scheduling in Laravel 8. We will build a demo app that will e-mail the weekly report of an employee’s task details to their manager.
  • 3. Task Scheduling in Laravel 8 Tutorial: What are we building? Create and Navigate to Laravel Project Create Controller: TaskAddController User Interface: Create Form Add Route Create Model and Migration Update Mail Class Create Artisan command Schedule command Conclusion CONTENTS 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
  • 5. Let’s clarify what we are going to build in the demo. The user interface will have a form that will take details (employee with tasks) and the manager’s email ID (to send a weekly report). After submitting the form, the report will automatically be generated and mailed to the manager at the end of the week.
  • 7. Let’s start a new Laravel project, for that run the below command in your cmd, composer create-project laravel/laravel task-scheduling-demo cd task-scheduling-demo
  • 9. After creating the database and adding mail configurations to the .env file, use the following command to create a controller. php artisan make:controller TaskAddController
  • 11. Moving towards the UI part. We need to create a form that will take employee and task details with the manager’s email ID (the report will be sent). Open welcome.blade.php and add below code in your tag. <div class="container"> @if (session('status')) <div class="alert alert-success"> {{ session('status') }} </div> @endif <form method="post" action=" {{route('addData')}}"> @csrf <h2>Employee Details</h2><br> <div class="form-group"> <label>Id</label>
  • 12. <input type="number" name="e_id" class="form-control" placeholder="Enter Employee_Id"> </div> <div class="form-group"> <label>Name</label> <input type="text" name="e_name" class="form-control" placeholder="Enter Your Name"> </div> <div class="form-group"> <label>Email address</label> <input type="email" name="e_email" class="form-control" placeholder="Enter Your Email"> </div>
  • 13. <div class="form-group"> <h2>Task Details</h2><br> <div class="form-group"> <label>Monday</label> <input type="text" name="t_mon" class="form-control" placeholder="Task done by Monday"> </div> <div class="form-group"> <label>Tuesday</label> <input type="text" name="t_tue" class="form-control" placeholder="Task done by Tuesday"> </div> <div class="form-group"> <label>Wednesday</label> <input type="text" name="t_wed" class="form-control" placeholder="Task done by Wednesday"> </div>
  • 14. <div class="form-group"> <label>Thursday</label> <input type="text" name="t_thu" class="form-control" placeholder="Task done by Thursday"> </div> <div class="form-group"> <label>Friday</label> <input type="text" name="t_fri" class="form-control" placeholder="Task done by Friday"> </div> </div> <div class="form-group"></div> <button type="submit" class="btn btn- primary">Submit</button> </form> </div>
  • 15. The UI will look something like this-
  • 17. For adding route, use below code in web.php file use AppHttpControllersTaskAddController; Route::post('/addData', [TaskAddController::class,'addTask'])- &gt;name('addData');
  • 19. In this step we will create one model and migration file to save the report of the employee. For that use the below command. php artisan make:model AddTask -m After creating the migration file, add table structure in it. <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema;
  • 20. class CreateAddTasksTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('add_tasks', function (Blueprint $table) { $table->id(); $table->bigInteger('e_id'); $table->string('e_name'); $table->string('e_email'); $table->string('manager_email'); $table->string('t_mon');
  • 21. $table->string('t_tue'); $table->string('t_wed'); $table->string('t_thu'); $table->string('t_fri'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('add_tasks'); } }
  • 22. Update Controller To update TaskAddController add below code: <?php namespace AppHttpControllers; use IlluminateHttpRequest; use AppModelsAddTask; class TaskAddController extends Controller { public function addTask(Request $request) { $data = $request->all(); $task = new AddTask(); $task->e_id = $data['e_id'];
  • 23. $task->e_name = $data['e_name']; $task->e_email = $data['e_email']; $task->manager_email = $data['manager_email']; $task->t_mon = $data['t_mon']; $task->t_tue = $data['t_tue']; $task->t_wed = $data['t_wed']; $task->t_thu = $data['t_thu']; $task->t_fri = $data['t_fri']; $task->save(); return back()->with('status','Data added successfully'); } }
  • 25. Now we create a mail class with a markdown. For that apply the below command. php artisan make:mail WeeklyReport -- markdown=emails.weeklyReport
  • 27. After creating, update the mail class. Open AppMailWeeklyReport.php <?php namespace AppMail; use IlluminateBusQueueable; use IlluminateContractsQueueShouldQueue; use IlluminateMailMailable; use IlluminateQueueSerializesModels; class WeeklyReport extends Mailable { use Queueable, SerializesModels; public $body; /** * Create a new message instance.
  • 28. * * @return void */ public function __construct($body) { $this->body = $body; } /** * Build the message. * * @return $this */ public function build() { return $this- >markdown('email.weeklyReport'); } }
  • 29. For creating mail structure, open viewsemailweeklyReport.blade.php Hello.. This mail contains Weekly report of your Team. <style> table, th, td { border: 1px solid black; } table { width: 100%; border-collapse: collapse; } </style> <table > <thead> <tr>
  • 33. For sending the weekly report we need to create an artisan command . Use the following the command for the same php artisan make:command sendWeeklyReport Now go to the AppConsoleCommandssendWeeklyRepo rt.php and add the below code. The handle() method of this class gets all the data from the database; for each employee report will be generated and sent to the email ID provided in the form, here manager’s email ID.
  • 34. <?php namespace AppConsoleCommands; use IlluminateConsoleCommand; use AppModelsAddTask; use AppMailWeeklyReport; use Mail; class sendWeeklyReport extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'weekly:mail_report'; /** * The console command description. * * @var string */
  • 35. protected $description = 'Weekly report send to Manager'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return int */ public function handle() { $emp = AddTask::all();
  • 36. foreach($emp as $empl) { $email = $empl->manager_email; $body = $empl; Mail::to($email)->send(new WeeklyReport($body)); $this->info('Weekly report has been sent successfully'); } } }
  • 38. Open AppConsoleKernal.php and update the schedule method of that class to add a scheduler. protected function schedule(Schedule $schedule) { $schedule- >command('weekly:mail_report')- >weekly(); } To run the scheduler locally, use the following command php artisan schedule:work You can check the Laravel official documentation for exploring more about Task scheduling in Laravel 8.
  • 39. Open terminal and run crontab -e. So far, we have defined our scheduled tasks; now, let’s see how we can run them on the server. The artisan command schedule:run evaluates all the scheduled tasks and determines whether they need to be run on the server’s current time. To set up crontab, use the following instructions- Setup Crontab
  • 40. Add the below line to the file. Save the file. * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
  • 41. Run the project php artisan serve Fill the required details as shown below-
  • 42. On submitting the form, the email will be sent.
  • 44. So, this was about how to implement Task scheduling in Laravel 8. For more such tutorials, visit Laravel Tutorials Page and clone the github repository to play around with the code. If you have any queries or requirements for your Laravel project, feel free to connect with Bacancy to hire Laravel developers.