Skip to content

Commit

Permalink
Merge pull request #3 from hanisirfan/visitor_add
Browse files Browse the repository at this point in the history
Visitor add
  • Loading branch information
hanisirfan authored Nov 16, 2022
2 parents 9877129 + c6eb415 commit f473c21
Show file tree
Hide file tree
Showing 19 changed files with 1,052 additions and 258 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
1. Web server with PHP version ^8.1 support.
2. PHP extensions: curl, exif, fileinfo, gd, intl, mbstring, mysqli, openssl, pdo_mysql, sodium, xsl

I listed every extensions enabled on my development environment. I don't really know what extensions required for packages the installed :laughing:
I listed every extensions enabled on my development environment. I don't really know what extensions required for the packages installed :laughing:

3. NodeJS version ^14.18.0.
4. Composer version ^2.3.10

## Project installation

1. Copy `.env.example` file and rename it to `.env`.
2. Create a new database and set the newly created database details inside `.env` file.
2. Run these commands to compile the assets and install the project.
1. Download the release or clone this project inside your web server root folder. Make sure Virtualhost / Server block is configured correctly to point `/public` as document root.
2. Copy `.env.example` file and rename it to `.env`.
3. Create a new database and set the newly created database credentials inside `.env` file.
4. Run these commands to compile the assets and install the project.

`composer compile-project`
`composer compile-project`

`php artisan install PASSWORD USER_NAME EMAIL_ADDRESS`
`php artisan install PASSWORD USER_NAME EMAIL_ADDRESS`

## Copyright

Expand Down
12 changes: 10 additions & 2 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Visitor;
use Illuminate\Http\Request;

class HomeController extends Controller
Expand All @@ -21,8 +22,15 @@ public function __construct()
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
public function index(Request $request)
{
return view('home');
if ($request->isMethod('get')) {
$pagination = 5;

$visitors = Visitor::orderBy('created_at', 'DESC')->paginate($pagination)->withQueryString();

return view('home')->with(['visitors' => $visitors]);
}

}
}
33 changes: 0 additions & 33 deletions app/Http/Controllers/QRFormsController.php

This file was deleted.

84 changes: 84 additions & 0 deletions app/Http/Controllers/VisitorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Http\Controllers;

use App\Models\Visitor;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use chillerlan\QRCode\QRCode;
use Illuminate\Support\Facades\Auth;

class VisitorController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(Request $request, $uuid)
{
if ($request->isMethod('get')) {
// Check if visitor exists.
if (Visitor::where('uuid', $uuid)->first()) {
$visitor = Visitor::where('uuid', $uuid)->first();

return view('visitors.view')->with(['visitor' => $visitor]);
} else {
return abort(404);
}
}
}

public function create(Request $request)
{

if ($request->isMethod('post')) {

$validated = $request->validate([
'visitor-name' => ['required'],
'visitor-ic-number' => ['required'],
'visitor-vehicle-plate-number' => ['required'],
'visitor-datetime' => ['required'],
]);

$uuid = (string) Str::uuid();
$name = $request->input('visitor-name');
$icNumber = $request->input('visitor-ic-number');
$plateNumber = $request->input('visitor-vehicle-plate-number');
$accessDateTime = $request->input('visitor-datetime');
$userName = Auth::user()->name;

$visitor = Visitor::create([
'uuid' => $uuid,
'name' => $name,
'ic_number' => $icNumber,
'vehicle_plate_number' => $plateNumber,
'visit_datetime' => $accessDateTime,
'added_by' => $userName,
]);

$request->session()->flash('addVisitorSuccess', 'Visitor successfully added!');

// Reference: https://startutorial.com/view/php-qr-code-generator-with-source-code
$qrCode = (new QRCode())->render('visitorqr: ' . $uuid);
$request->session()->flash('qrCode', $qrCode);
$request->session()->flash('uuid', $uuid);

return back();
}

if ($request->isMethod('get')) {
return view('visitors.add');
}
}
}
63 changes: 63 additions & 0 deletions app/Models/Visitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace App\Models;

use DateTime;
use chillerlan\QRCode\QRCode;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Visitor extends Model
{
use HasFactory;
use HasUuids; // Use UUID instead of auto incremented IDs.

protected $primaryKey = 'uuid';

protected $appends = ['qr', 'date_time'];

/**
* Generate QR based on UUIDs
*
*/
public function getQRAttribute() {
return (new QRCode())->render('visitorqr: ' . $this->uuid);
}

/**
* Generate QR based on UUIDs
*
*/
public function getDateTimeAttribute() {
return new DateTime($this->visit_datetime);
}

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'uuid',
'name',
'ic_number',
'vehicle_plate_number',
'visit_datetime',
'added_by',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [];
}
3 changes: 2 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand All @@ -23,6 +24,6 @@ public function register()
*/
public function boot()
{
//
Paginator::useBootstrapFive();
}
}
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"license": "MIT",
"require": {
"php": "^8.0.2",
"blade-ui-kit/blade-ui-kit": "^0.3.4",
"chillerlan/php-qrcode": "^4.3",
"doctrine/dbal": "^3.5",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.19",
"laravel/sanctum": "^3.0",
Expand Down
Loading

0 comments on commit f473c21

Please sign in to comment.