How to Send email with Attachement in Laravel 5.8

In this tutorial i’m going to describe how to send attachement in laravel, please follow some easy steps define below.

First let’s go to install laravel project

composer create-project laravel/laravel learning-project "5.8.*"

lets go to .env folder and put database name and connect to database.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=learning-project
DB_USERNAME=root
DB_PASSWORD=

Now migrate the table

php artisan migrate

Create a Mailable class first you have to create an account in mailtrap or click this url https://mailtrap.io/ after create account you have to copy Username: XXXXXXXXX and password: XXXXXXXXXX and put in .env file see pic

Now we are ready for make mailable class for this we have to go teminal and write following

Let’s go to create controller

php artisan make:controller PDFController

Go to your PDF controller file and paste below code

<?php

namespace App\Http\Controllers;
use Log;
use PDF;
use Mail;

class PDFController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$data["email"] = "laravelamit@gmail.com";
$data["title"] = "From DevOpsSchool.com";
$data["body"] = "This is Demo";

$files = [
public_path('files/yit-brochure.pdf'),
public_path('files/laravel.png'),
];
// log::info('mail aa rha hai');
Mail::send('emails.myTestMail', $data, function($message)use($data, $files) {
$message->to($data["email"], $data["email"])
->subject($data["title"]);

foreach ($files as $file){
$message->attach($file);
}

});

dd('Mail sent successfully');
}
}

Next to create view files

resources/views/emails/myTestMail.blade.php

Go to your myTestMail.blade file and paste below code

<!DOCTYPE html>
<html>
<head>
<title>Laravel Amit</title>
</head>
<body>
<h1>{{ $title }}</h1>
<p>{{ $body }}</p>

<p>Thank you</p>
</body>
</html>

And lastone go to Routes/web.php and paste below code.

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PDFController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

Auth::routes(['verify' => true]);

Route::get('/home', 'HomeController@index')->name('home');
Route::get('/send-email-pdf', 'PDFController@index')->name('sendemail');

Now refresh your browser and check.

Thanks …

Tagged : / / /

What is JaveScript?

JavaScript is the programming language of HTML and the Web. It makes the web pages dynamic. It is an interpreted programming language with object-oriented capabilities. JavaScript is also known as client-side language. This is the client site language itself. But some people also call it server site language.

The meaning of the client site which is accessed by the user is called client site language. And what runs in the server is called the server-side language.

JaveScript History

  • JavaScript was introduced in 1995 by Netscape. And it was developed by Brendan Eich.
  • It was first named Mocha.
  • After that its name was changed to Livescript.
  • Then javascript.
  • Then it came to be called Ekamscript. But still people call it JavaScript only.
  • There is a 5,6 version of Ekscript. May have come in 2009.

Tools

  • Notepad
  • Notepad++
  • Any Text Editor

JavaScrips and Java Same?

No, Only java has similarities in JavaScript and java, apart from this there are no similarities in it.

Java programming language was very popular when Javascripts was being launched in the market, so they merged java with them, and then it was named JavaScript.

Advantage of JavaScript

  • Client Side execution
  • Velidation on Browser
  • easy language

Disadvantage of JavaScript

  • Less Secure
  • No Hardware Access

Why of adding JavaScript

Here too, if you want to use JavaScript, then you have to link both the files through your HTML. And it has its own different rules.

  • Inline

-Inside head tag
-inside body tag

  • External file

-Inside head Tag

-Inside body Tag

Inline

You can write inline in 2 ways, inline and external.

Inside head Tag –

<html>
	<head><title>Hello JS</title>
		<script type="text/javascript">
			document.write("Hello DevOpSchool");
		</script>
	</head>
	</body>
`		<h1>I am heading</h1>
		<p>I am Paraghraph</p>
	</body>
	
</html>

Inside body tag

<html>
	<head><title>Hello JS</title>
		
	</head>
	</body>
`		<h1>I am heading</h1>
		<p>I am Paraghraph</p>
		<script type="text/javascript">
			document.write("Hello DevOpSchool");
		</script>
	</body>
	
</html>

External

Inside head tag

<html>
	<head><title>Hello JS</title>
		<script src="name.js" type="text/javascript">
		</script>
	</head>
	</body>
`		<h1>I am heading</h1>
		<p>I am Paraghraph</p>
		
	</body>
	
</html>

*Save with .js extension
Ex:- name.js

*Now link this file to HTML

Inside Body tag

<html>
	<head><title>Hello JS</title>
		
	</head>
	</body>
`		<h1>I am heading</h1>
		<p>I am Paraghraph</p>
		
		<script src="name.js" type="text/javascript">
		</script>
	</body>
	
</html>

*Save with .js extension
Ex:- name.js

*Now link this file to HTML

Tagged : / / / / / /

How to create manual pagination with search filter in Laravel API?

When you are using To Laravel Project with Connect to Api. Then pagination and search filter (laravel default) will not work in this process. So, you can use DataTable or Manual. So in this blog I am using manual.

This is a Search Input filter

This is Pagination

This is Js in script tag

This is First Laravel Project Controller Function for sending requests for pagination and Search Filter.

This is Second Project Controller Function for pagination and search filter.

Tagged : / / / / /