Skip to content

Instantly share code, notes, and snippets.

@introwit
introwit / helper.php
Created October 28, 2015 10:56
Display Greetings (Morning/Evening)
<?php
/* This sets the $time variable to the current hour in the 24 hour clock format */
$time = date("H");
/* Set the $timezone variable to become the current timezone */
$timezone = date("e");
/* If the time is less than 1200 hours, show good morning */
if ($time < "12") {
echo "Good morning";
} else
/* If the time is grater than or equal to 1200 hours, but less than 1700 hours, so good afternoon */
@introwit
introwit / RegisterController.php
Last active October 11, 2016 16:38
Email verification blog - gist 1
<?php
/**
* Create a new user instance after a valid registration with a random email token
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
@introwit
introwit / RegisterController2.php
Last active May 3, 2017 00:00
Email verification blog - gist 2
<?php
/**
* Over-ridden the register method from the "RegistersUsers" trait
* Remember to take care while upgrading laravel
*/
public function register(Request $request)
{
// Laravel validation
$validator = $this->validator($request->all());
@introwit
introwit / EmailVerification.php
Last active October 11, 2016 16:37
Email verification blog - gist 3
<?php
namespace App\Mail;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
@introwit
introwit / verification.blade.php
Created October 11, 2016 15:41
Email verification blog - part 4
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css" rel="stylesheet" media="all">
/* Media Queries */
@media only screen and (max-width: 500px) {
@introwit
introwit / RegisterControllerVerify.php
Last active October 18, 2016 10:15
Email verification blog - Part 5
<?php
// Get the user who has the same token and change his/her status to verified i.e. 1
public function verify($token)
{
// The verified method has been added to the user model and chained here
// for better readability
User::where('email_token',$token)->firstOrFail()->verified();
return redirect('login');
@introwit
introwit / User.php
Last active October 11, 2016 16:37
Email Verification blog - 6
<?php
// Set the verified status to true and make the email token null
public function verified()
{
$this->verified = 1;
$this->email_token = null;
$this->save();
}
<?php
namespace App\Http\Controllers\Auth;
use DB;
use Mail;
use App\User;
use Validator;
use Illuminate\Http\Request;
use App\Mail\EmailVerification;
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
<?php
public function credentials(Request $request)
{
return [
'email' => $request->email,
'password' => $request->password,
'verified' => 1,
];
}