SlideShare una empresa de Scribd logo
1 de 45
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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 8Raja 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 TutorialJoe 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 ArtisansRaf 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 PecoraroChristopher Pecoraro
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentationToufiq Mahmud
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel frameworkAhmad Fatoni
 
Laravel5 Introduction and essentials
Laravel5 Introduction and essentialsLaravel5 Introduction and essentials
Laravel5 Introduction and essentialsPramod 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 5Darren Craig
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingChristopher Pecoraro
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should knowPovilas Korop
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJSBlake Newman
 

La actualidad más candente (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 a Task scheduling in laravel 8 tutorial

Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAlfa 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 exampleKaty Slemon
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
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.pptxBOSC Tech Labs
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna 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 + TypeScriptKaty Slemon
 
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 EngineMichael 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
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentationdharisk
 
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 2016Nicolás Bouhid
 

Similar a 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
 

Más de 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty Slemon
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty 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.pdfKaty Slemon
 

Más de 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
 

Último

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 

Último (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

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.