Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_NAME=Laravel
APP_NAME=Property
APP_ENV=local
APP_KEY=
APP_KEY=base64:8zXXBRoELgRkLGo/TVSR7Fiy8yb2yckieypH1PySibM=
APP_DEBUG=true
APP_URL=http://localhost

Expand All @@ -15,20 +15,22 @@ DB_CONNECTION=sqlite

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_PORT=587
MAIL_USERNAME=1b9337954c9df9
MAIL_PASSWORD=30e865f8017ebc
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=from@example.com
MAIL_FROM_NAME=Example

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
Expand All @@ -42,3 +44,5 @@ PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

POST_CODE_SERVICE_URL=http://api.postcodes.io/postcodes/:postcode/validate
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ npm-debug.log
yarn-error.log

/public/

/storage/logs/

/.idea
/.vscode
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# Laravel Coding Test
## Coding Test

You should have been told which set of tasks to complete. If not please let your contact know.

Feel free to do both sets if you want.
##### Setup project

## Backend

1. Add a page for users to register
2. Use http://postcodes.io/ to ensure that users submit a valid postcode
3. Send a welcome email when a user is registered
4. Add an artisan command to list recently registered users

## Frontend

Start the development server using `php artisan serve` and go to http://127.0.0.1:8000/address

1. Make the address lookup component accessible
2. Style it using bootstrap
1. Clone project
2. Copy .env.example file to .env on the root folder.
```shell
$ composer install
$ php artisan key:generate
$ php artisan migrate
$ php artisan serve
#make sure to run queue:work in order to receive notifications
$ php artisan queue:work
#you can add limit to users:list command
$ php artisan users:list 10
```
55 changes: 55 additions & 0 deletions app/Console/Commands/UsersList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Console\Commands;

use App\User;
use Illuminate\Console\Command;

class UsersList extends Command
{
const TABLE_COLUMNS = ['id', 'name', 'email', 'postcode', 'created_at'];

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'users:list {limit?}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Listing users registered recently with count as optional.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{

$data = User::latest()->limit($this->argument('limit'))->get(self::TABLE_COLUMNS)->toArray();
if (count($data)) {
$this->table(array_map('ucfirst', self::TABLE_COLUMNS), $data);
} else {
$this->info("Didn't find any registered users!");
}

$this->info('The users:list command did successfully retrieve last '. count($data) . ' registered users');

return 0;
}
}
6 changes: 2 additions & 4 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
//
'App\Console\Commands\UsersList',
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @param Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Handler extends ExceptionHandler
/**
* Report or log an exception.
*
* @param \Throwable $exception
* @param Throwable $exception
* @return void
* @throws Throwable
*/
Expand All @@ -44,11 +44,11 @@ public function report(Throwable $exception)
* Render an exception into an HTTP response.
*
* @param Request $request
* @param \Throwable $exception
* @param Throwable $exception
* @return Response
* @throws Throwable
*/
public function render($request, Throwable $exception): Response
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/ConfirmPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ConfirmsPasswords;

class ConfirmPasswordController extends Controller
Expand All @@ -25,7 +26,7 @@ class ConfirmPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
Expand All @@ -25,7 +26,7 @@ class LoginController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
Expand Down
11 changes: 8 additions & 3 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Rules\PostCode;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
Expand All @@ -28,7 +30,7 @@ class RegisterController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
Expand All @@ -52,20 +54,23 @@ protected function validator(array $data)
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'postcode' => ['bail', 'required', 'string', 'max:255', new PostCode],

]);
}

/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
* @return User
*/
protected function create(array $data)
protected function create(array $data): User
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'postcode' => $data['postcode'],
'password' => Hash::make($data['password']),
]);
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ResetsPasswords;

class ResetPasswordController extends Controller
Expand All @@ -25,5 +26,5 @@ class ResetPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/VerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\VerifiesEmails;

class VerificationController extends Controller
Expand All @@ -25,7 +26,7 @@ class VerificationController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
Expand Down
19 changes: 19 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Contracts\Support\Renderable;

class HomeController extends Controller
{

/**
* Show the application dashboard.
*
* @return Renderable
*/
public function index(): Renderable
{
return view('home');
}
}
9 changes: 5 additions & 4 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @param Request $request
* @param Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
public function handle(Request $request, Closure $next, string $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
Expand Down
Loading