What is a Framework in Laravel?

What is a Framework?

A framework is a set of conceptual structures and guidelines, used to build something. A framework may include predefined classes and functions that can be used to process input, manage hardware devices, and interact with system software. The purpose of the framework is to allow developers to focus on building a unique feature for their projects rather than writing code from scratch.

Why use Framework?

  • Colection of tools
  • No need to start scratch
  • Save Time
  • Improve Productivity
  • Clean Code
  • Reusable Code
  • Testing
  • Debugging

What is Web Framework?

A Web Framework or web application helps to build Web Applications. A Web framework provides tools and libraries to simplify common web development operations. This can include web services, APIs, and other resources. Web Framework help with a variety of tasks, from templating and database access to session management and code reuse. More than 80% of web app frameworks follow the Model View Controller architecture.

Some Web Framework

  • Laravel
  • Codeigniter
  • Zend
  • Django
  • Spring
Tagged : /

Complete Referance of Controller in Laravel

Controllers

Controllers can group related request handling logic into a single class. Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes.

Controllers are stored in the app/Http/Controllers directory.
Controller extends the base Controller class included with Laravel.

Defining Controller Class

Run Command:- php artisan make:controller

Example:- php artisan make:controller AboutController

Path:- app/Http/Controllers/AboutController.php

Creating Route for Controller Class

Path of Controller :- app/Http/Controllers/AboutController.php

Path of Route:- routes/web.php

Syntax:- Route::get(‘uri’, [ControllerName::class, ‘method_name’]);

Passing Data from Controller to View

Path of Controller :- app/Http/Controllers/AboutController.php

Path of Route:- routes/web.php

Path of View:- resources/views/aboutme.blade.php

Multiple Methods inside Controller

Path of Controller :- app/Http/ControllersAboutController.php

Path of Route:- routes/web.php

Path of aboutme blade file:- resources/views/aboutme.blade.php

Path of aboutyou blade file:- resources/views/aboutyou.blade.php

Single Action Controller

If you would like to define a controller that only handles a single action, you may place a single __invoke method on the controller.

Run Command:- php artisan make:controller ShowAbout –invokable

Path of Controller :- app/Http/Controllers/ShowAboutController.php

Path of Route:- routes/web.php

Path of aboutme blade file:- resources/views/aboutme.blade.php

Tagged : /

How to Install Laravel and Create Project

How to Install Laravel

  • Download the Laravel installer using Composer :
composer global require laravel/installer
  • Then use laravel new command will create a fresh Laravel installation in the directory you specify
laravel new projectname
  • Install Laravel by issuing the Composer create-project command
composer create-project --prefer-dist laravel/laravel projectname
Tagged : /

What is Laravel?

Laravel is a free, open-source PHP based Web Framework for building High End Web Applications, following the Model View Controller architectural pattern and based on Symfony.
It is created by Taylor Otwell.
Laravel Source Code : https://github.com/laravel/framework

Advantages of Laravel

  • Open Source
  • Collection of tools
  • Save Time
  • Improve Productivity
  • Robust and Easy
  • Security of the Application
  • Authentication
  • Routing
  • Templating
Tagged : /

Complete Referance of MVC Design Pattern

Model View Controller (MVC)

The MVC is an architectural pattern that separates an application into three main logical components Model, View, and Controller.
Each of these component has their own role in a Project.
MVC model was first introduced in 1987 in the Smalltalk programming language.
More than 80% of all web app frameworks rely on the Model View Controller architecture.

Model

The model is responsible for getting data from a database, packaging it in data objects that can be understood by other components, and delivering those objects, most of which will happen in response to input from the controller.

View

It represents how data should be presented to the application user. User can read or write the data from view.
Basically it is responsible for showing end user content, we can say it is user interface.
It may consists of HTML, CSS, JS.

Controller

The user can send request by interacting with view, the controller handles these requests and sends to Model then get appropriate response from the Model, sends response to View.
It may also have required logics.
It works as a mediator between View and Model.

Why use MVC?

  • Organized Code
  • Independent Block
  • Reduces the complexity of web applications
  • Easy to Maintain
  • Easy to modify

Basic Structure

  • Assets
    • CSS
    • Images
    • JS
  • Config
    • Database Config File
  • Controllers
  • Model
  • Views
Tagged : /

PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version “>= 7.2.5”. You are running 7.1.32.

When you using PHP version 7.1.32 within your Laravel project, then showing this type of error in your project. If you want to update the composer still not solve you problem then After that Follow this trick-

add this line in config object of composer.json file

“platform-check”: false

run php artisan config:cache

then run composer dump-autoload in terminal

Tagged : / / / / / / / / / /

What is a Web Framework, Why do we use Web Frameworks?

What is a Web Framework?

A Web Framework (WF) or Web Application Framework (WAF) which helps to build Web Applications.
Web frameworks provide tools and libraries to simplify common web development operations. This can include web services, APIs, and other resources.
Web frameworks help with a variety of tasks, from templating and database access to session management and code reuse.
More than 80% of all web app frameworks rely on the Model View Controller architecture.

Why do we use Web Frameworks?

  • Collection of tools
  • No need to start from scratch
  • Save Time
  • Improve Productivity
  • Clean Code
  • Reusable Code
  • Testing
  • Debugging

Some Web Framework

  • Laravel
  • Codeigniter
  • Zend
  • Django
  • Spring
Tagged : / / /

Upload Document and send Mail in Laravel | How to send attachment files to email using laravel ?

In this tutorial im going to demonstrate how to upload document and send data via Email. Please follow some easy steps mentioned 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=

Let’s to create Controller

php artisan make:controller SendEmailController

Go to your controller SendEmailController and paste below code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Mail\SendMail;
use App\UploadImage;

class SendEmailController extends Controller
{

function index()
{
return view('send_email');
}
public function store(Request $request){
$request->validate([
'name'=>'required',
'email' => 'required',
'image'=> 'required',
]);

$resume = time() . '.' . $request['image']->getClientOriginalExtension();
$imagesendbymailwithstore= new UploadImage();
$imagesendbymailwithstore->name = $request->name;
$imagesendbymailwithstore->email = $request->email;
$imagesendbymailwithstore->image = $resume;
$imagesendbymailwithstore->save();

// for mailling function working
$imagesendbymailwithstore = array(
'name' => $request->name,
'email' => $request->email,
'image' => $request->image,

);
Mail::to($imagesendbymailwithstore['email'])->send(new SendMail($imagesendbymailwithstore));
$request['image']->move(base_path() . '/storage/app/public', $resume);
return back()->with('success', 'Thanks for contacting us!');
}
}

Next create model and migration file so run below code.

php artisan make:model UploadImage -m

Next step go to your migration and and table

database\migrations\2020_10_23_070450_create_upload_images_table.php

Add follow column name

$table->string('name');
$table->string('email');
$table->string('image');

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

Then make a view page send_email.blade.php

<!DOCTYPE html>
<html>
<head>
<title> send a mail with Attachment </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
.box{
width:600px;
margin:0 auto;
border:1px solid #ccc;
}
.has-error
{
border-color:#cc0000;
background-color:#ffff99;
}
</style>
</head>
<body>
<br />
<br />
<br />
<div class="container box">
<h3 align="center">send a mail with Attachment using laravel 5.8</h3><br />
@if (count($errors) > 0)
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
@if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif

<form method="post" action="{{ route('sendemail.store') }}" enctype="multipart/form-data" role="form" class="form-horizontal" id="location">
{{ csrf_field() }}
<div class="form-group">
<label>Enter Your Name</label>
<input type="text" name="name" class="form-control" value="" />
</div>
<div class="form-group">
<label>Enter Your Email</label>
<input type="text" name="email" class="form-control" value="" />
</div>

<div class="form-group">
<label for="resume" placeholder="(resume type *PDF*)">Document:<span class="text-danger font-weight-bold">*</span></label>
<input type="file" class="w-100 p-1" name="image" value="{{old('resume')}}"/>
<label class="text-danger mt-1" >(*File type- PDF & Maximum size 1 MB*)</label>
</div>
<div class="form-group">
<input type="submit" name="send" class="btn btn-info" value="Send" />
</div>
</form>

</div>
</body>
</html>

Next step make one blade page resources/view/dynamic_email_template.blade.php

<p style="margin-left:10%;">First Name - <b>{{ $data['name'] }} </b></p>
<p style="margin-left:10%;">last Name - <b>{{ $data['email'] }} </b></p>


<p>It would be appriciative, if you gone through this feedback.</p>

Next one to create SendMail.php file run below code.

php artisan make:mail SendMail

Next step go to App\Mail\SendMail.php and paste below code

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendMail extends Mailable
{
use Queueable, SerializesModels;
public $imagesendbymailwithstore;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($imagesendbymailwithstore)
{
$this->imagesendbymailwithstore = $imagesendbymailwithstore;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('info@scmgalaxy.com')
->subject('New image from Devops Team')
->view('dynamic_email_template')
->with('data', $this->imagesendbymailwithstore)
->attach($this->imagesendbymailwithstore['image']->getRealPath(),
[
'as' => $this->imagesendbymailwithstore['image']->getClientOriginalName(),
'mime' => $this->imagesendbymailwithstore['image']->getClientMimeType(),
]);

}
}

Next define routes go to your routes/web.php file and paste below code.

Route::get('sendemail','SendEmailController@index');
Route::post('sendemail.store','SendEmailController@store')->name('sendemail.store');

Now run below code and refresh your browser and fill form

php artisan servehttp://127.0.0.1:8000

Now form look- like this

Thanks i hope its helpfull for you 🙏🙏

Tagged : / / /

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 : / / /