From 06369b52426626ab7fb22c3cf0bdf9df71fe7fff Mon Sep 17 00:00:00 2001 From: "aragab@teendegrees.sa" Date: Fri, 21 Jan 2022 21:01:25 +0200 Subject: [PATCH 01/12] first commit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a634524..2639a64 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ npm-debug.log yarn-error.log /public/ +/nbproject/ From 77aaa286b1f3b058a1e06d9d9e0a449f8fd7059c Mon Sep 17 00:00:00 2001 From: "aragab@teendegrees.sa" Date: Fri, 21 Jan 2022 21:28:34 +0200 Subject: [PATCH 02/12] change db to mysql --- .env.example | 2 +- .gitignore | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 9eea31a..5f89e6c 100644 --- a/.env.example +++ b/.env.example @@ -6,7 +6,7 @@ APP_URL=http://localhost LOG_CHANNEL=stack -DB_CONNECTION=sqlite +DB_CONNECTION=mysql #DB_HOST=127.0.0.1 #DB_PORT=3306 #DB_DATABASE=laravel diff --git a/.gitignore b/.gitignore index 2639a64..232c3a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /node_modules /public/hot /public/storage -/storage/*.key +/storage/ /vendor .env .env.backup From a73a3949b822284357b6ff59e2841b84c29604a7 Mon Sep 17 00:00:00 2001 From: "aragab@teendegrees.sa" Date: Fri, 21 Jan 2022 21:39:12 +0200 Subject: [PATCH 03/12] add users controller --- app/Http/Controllers/UsersController.php | 84 ++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 app/Http/Controllers/UsersController.php diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php new file mode 100644 index 0000000..6a4c807 --- /dev/null +++ b/app/Http/Controllers/UsersController.php @@ -0,0 +1,84 @@ + Date: Fri, 21 Jan 2022 21:42:06 +0200 Subject: [PATCH 04/12] add base repo --- app/Repositories/BaseRepository.php | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/Repositories/BaseRepository.php diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php new file mode 100644 index 0000000..521daba --- /dev/null +++ b/app/Repositories/BaseRepository.php @@ -0,0 +1,32 @@ +model = $model; + } + + public function all() { + return $this->model->all(); + } + +} From dbe68f77bf485a8cb23c3bee45c922e54ecb74ce Mon Sep 17 00:00:00 2001 From: Aly Ragab Date: Fri, 21 Jan 2022 21:48:20 +0200 Subject: [PATCH 05/12] add users repo and move models --- app/{ => Models}/User.php | 2 +- app/Repositories/UsersRepositories.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) rename app/{ => Models}/User.php (97%) create mode 100644 app/Repositories/UsersRepositories.php diff --git a/app/User.php b/app/Models/User.php similarity index 97% rename from app/User.php rename to app/Models/User.php index e79dab7..59df870 100644 --- a/app/User.php +++ b/app/Models/User.php @@ -1,6 +1,6 @@ Date: Fri, 21 Jan 2022 23:23:53 +0200 Subject: [PATCH 06/12] start to build the main dependencies for the logic --- app/Http/Controllers/UsersController.php | 66 +-- app/Http/Requests/StoringUserRequest.php | 38 ++ app/Models/User.php | 7 +- app/Rules/PostCode.php | 40 ++ app/helpers.php | 33 ++ composer.json | 4 + composer.lock | 529 ++++++++++++++++++++++- resources/views/layout.blade.php | 62 +++ resources/views/register.blade.php | 78 ++++ routes/web.php | 20 +- 10 files changed, 803 insertions(+), 74 deletions(-) create mode 100644 app/Http/Requests/StoringUserRequest.php create mode 100644 app/Rules/PostCode.php create mode 100644 app/helpers.php create mode 100644 resources/views/layout.blade.php create mode 100644 resources/views/register.blade.php diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 6a4c807..c717203 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -4,26 +4,15 @@ use Illuminate\Http\Request; -class UsersController extends Controller -{ - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() - { - // - } +class UsersController extends Controller { /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ - public function create() - { - // + public function create() { + return view('register'); } /** @@ -32,53 +21,8 @@ public function create() * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ - public function store(Request $request) - { - // + public function store(Request $request) { + dd($request); } - /** - * Display the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function show($id) - { - // - } - - /** - * Show the form for editing the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function edit($id) - { - // - } - - /** - * Update the specified resource in storage. - * - * @param \Illuminate\Http\Request $request - * @param int $id - * @return \Illuminate\Http\Response - */ - public function update(Request $request, $id) - { - // - } - - /** - * Remove the specified resource from storage. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function destroy($id) - { - // - } } diff --git a/app/Http/Requests/StoringUserRequest.php b/app/Http/Requests/StoringUserRequest.php new file mode 100644 index 0000000..95090be --- /dev/null +++ b/app/Http/Requests/StoringUserRequest.php @@ -0,0 +1,38 @@ + ['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], + ]; + } + +} diff --git a/app/Models/User.php b/app/Models/User.php index 59df870..db9b403 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,8 +6,8 @@ use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -class User extends Authenticatable -{ +class User extends Authenticatable { + use Notifiable; /** @@ -16,7 +16,7 @@ class User extends Authenticatable * @var array */ protected $fillable = [ - 'name', 'email', 'password', + 'name', 'email', 'password', 'postcode' ]; /** @@ -36,4 +36,5 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + } diff --git a/app/Rules/PostCode.php b/app/Rules/PostCode.php new file mode 100644 index 0000000..b38ba7d --- /dev/null +++ b/app/Rules/PostCode.php @@ -0,0 +1,40 @@ + $headers]); + $response = $client->get($uri, $options); + + return [ + 'response' => json_decode( + $response->getBody()->getContents(), + true + ), + 'status' => true + ]; + } catch (\Exception $exception) { + return [ + 'response' => ['message' => $exception->getMessage()], + 'status' => false + ]; + } + } + +} \ No newline at end of file diff --git a/composer.json b/composer.json index 7eec416..119ad66 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "require": { "php": "^7.2", "fideloper/proxy": "^4.0", + "guzzlehttp/guzzle": "^7.4", "laravel/framework": "^7.0", "laravel/tinker": "^2.0" }, @@ -33,6 +34,9 @@ "psr-4": { "App\\": "app/" }, + "files": [ + "app/helpers.php" + ], "classmap": [ "database/seeds", "database/factories" diff --git a/composer.lock b/composer.lock index 6e92ade..509b61b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6e58de05a7bfbbbf003da7e9ed4d75dd", + "content-hash": "22090ab338d196d8dd6651618e89791e", "packages": [ { "name": "brick/math", @@ -427,6 +427,329 @@ }, "time": "2020-10-22T13:48:01+00:00" }, + { + "name": "guzzlehttp/guzzle", + "version": "7.4.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ee0a041b1760e6a53d2a39c8c34115adc2af2c79", + "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.5", + "guzzlehttp/psr7": "^1.8.3 || ^2.1", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "ext-curl": "*", + "php-http/client-integration-tests": "^3.0", + "phpunit/phpunit": "^8.5.5 || ^9.3.5", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.4.1" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2021-12-06T18:43:05+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "1.5.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da", + "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "symfony/phpunit-bridge": "^4.4 || ^5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/1.5.1" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2021-10-22T20:56:57+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "089edd38f5b8abba6cb01567c2a8aaa47cec4c72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/089edd38f5b8abba6cb01567c2a8aaa47cec4c72", + "reference": "089edd38f5b8abba6cb01567c2a8aaa47cec4c72", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.8 || ^9.3.10" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.1.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2021-10-06T17:43:30+00:00" + }, { "name": "laravel/framework", "version": "v7.30.4", @@ -1389,6 +1712,166 @@ }, "time": "2019-01-08T18:20:26+00:00" }, + { + "name": "psr/http-client", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/master" + }, + "time": "2020-06-29T06:28:15+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/master" + }, + "time": "2019-04-30T12:38:16+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/master" + }, + "time": "2016-08-06T14:39:51+00:00" + }, { "name": "psr/log", "version": "1.1.4", @@ -1565,6 +2048,50 @@ }, "time": "2021-10-10T13:37:39+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, { "name": "ramsey/collection", "version": "1.2.2", diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php new file mode 100644 index 0000000..d215a41 --- /dev/null +++ b/resources/views/layout.blade.php @@ -0,0 +1,62 @@ + + + + Laravel + + + + + + + + @yield('content') + + + diff --git a/resources/views/register.blade.php b/resources/views/register.blade.php new file mode 100644 index 0000000..2ec3197 --- /dev/null +++ b/resources/views/register.blade.php @@ -0,0 +1,78 @@ +@extends('layout') + +@section('content') +
+
+
+
+
+
Register
+
+ +
+ @csrf +
+ +
+ + @if ($errors->has('name')) + {{ $errors->first('name') }} + @endif +
+
+ +
+ +
+ + @if ($errors->has('email')) + {{ $errors->first('email') }} + @endif +
+
+ +
+ +
+ + @if ($errors->has('postcode')) + {{ $errors->first('postcode') }} + @endif +
+
+ +
+ +
+ + @if ($errors->has('password')) + {{ $errors->first('password') }} + @endif +
+
+ +
+ +
+ + @if ($errors->has('password_confirmation')) + {{ $errors->first('password_confirmation') }} + @endif +
+
+ + +
+ +
+
+ +
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 1a673a1..ab39912 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,15 +1,15 @@ only('create', 'store'); From e7563042e4b6dc3646e87461fe8a102ebcdb5cc1 Mon Sep 17 00:00:00 2001 From: Aly Ragab Date: Sat, 22 Jan 2022 02:04:06 +0200 Subject: [PATCH 07/12] create the user --- .env.example | 2 + app/Exceptions/Handler.php | 2 +- app/Http/Controllers/UsersController.php | 19 +++++-- app/Http/Requests/StoringUserRequest.php | 2 +- app/Observers/UserObserver.php | 63 ++++++++++++++++++++++++ app/Repositories/BaseRepository.php | 4 ++ app/Rules/PostCode.php | 27 ++++------ app/Services/CreatingUserService.php | 32 ++++++++++++ resources/views/register.blade.php | 6 +-- 9 files changed, 131 insertions(+), 26 deletions(-) create mode 100644 app/Observers/UserObserver.php create mode 100644 app/Services/CreatingUserService.php diff --git a/.env.example b/.env.example index 5f89e6c..9c7a57e 100644 --- a/.env.example +++ b/.env.example @@ -42,3 +42,5 @@ PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +POST_CODE_CHECK_URL=https://api.postcodes.io/postcodes/ diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7fb0864..7e463a4 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -48,7 +48,7 @@ public function report(Throwable $exception) * @return Response * @throws Throwable */ - public function render($request, Throwable $exception): Response + public function render($request, Throwable $exception) { return parent::render($request, $exception); } diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index c717203..c65543f 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -2,7 +2,8 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App\Http\Requests\StoringUserRequest; +use App\Services\CreatingUserService; class UsersController extends Controller { @@ -18,11 +19,21 @@ public function create() { /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request + * @param StoringUserRequestRequest $request + * @param CreatingUserService $service * @return \Illuminate\Http\Response */ - public function store(Request $request) { - dd($request); + public function store( + StoringUserRequest $request, + CreatingUserService $service + ) { + $user_saved = $service->execute($request->validated()); + if($user_saved){ + + } + + + } } diff --git a/app/Http/Requests/StoringUserRequest.php b/app/Http/Requests/StoringUserRequest.php index 95090be..bb170e4 100644 --- a/app/Http/Requests/StoringUserRequest.php +++ b/app/Http/Requests/StoringUserRequest.php @@ -1,6 +1,6 @@ model->all(); } + + public function create(array $data) { + return $this->model->create($data); + } } diff --git a/app/Rules/PostCode.php b/app/Rules/PostCode.php index b38ba7d..45d8250 100644 --- a/app/Rules/PostCode.php +++ b/app/Rules/PostCode.php @@ -4,17 +4,7 @@ use Illuminate\Contracts\Validation\Rule; -class PostCode implements Rule -{ - /** - * Create a new rule instance. - * - * @return void - */ - public function __construct() - { - // - } +class PostCode implements Rule { /** * Determine if the validation rule passes. @@ -23,9 +13,12 @@ public function __construct() * @param mixed $value * @return bool */ - public function passes($attribute, $value) - { - // + public function passes($attribute, $value) { + $response = guzzleGet( + ['Content-Type' => 'application/json'], + getenv('POST_CODE_CHECK_URL') . $value + ); + return $response['status']; } /** @@ -33,8 +26,8 @@ public function passes($attribute, $value) * * @return string */ - public function message() - { - return 'The validation error message.'; + public function message() { + return 'Invalid Postcode'; } + } diff --git a/app/Services/CreatingUserService.php b/app/Services/CreatingUserService.php new file mode 100644 index 0000000..a66feda --- /dev/null +++ b/app/Services/CreatingUserService.php @@ -0,0 +1,32 @@ +repo = $repo; + } + + /** + * + * @param array $inputs + * @return bool + */ + public function execute(array $inputs): bool { + $inputs['password'] = Hash::make($inputs['password']); + $user = $this->repo->create($inputs); + return ($user instanceof User); + } + +} diff --git a/resources/views/register.blade.php b/resources/views/register.blade.php index 2ec3197..e746ea3 100644 --- a/resources/views/register.blade.php +++ b/resources/views/register.blade.php @@ -14,7 +14,7 @@
- + @if ($errors->has('name')) {{ $errors->first('name') }} @endif @@ -24,7 +24,7 @@
- + @if ($errors->has('email')) {{ $errors->first('email') }} @endif @@ -34,7 +34,7 @@
- + @if ($errors->has('postcode')) {{ $errors->first('postcode') }} @endif From 27b9bc3dd3ea674f34064ed13d1c0bf9e9dcc2f2 Mon Sep 17 00:00:00 2001 From: Aly Ragab Date: Sat, 22 Jan 2022 02:56:04 +0200 Subject: [PATCH 08/12] finish the registration cycle --- .env.example | 2 +- app/Http/Controllers/UsersController.php | 8 ++-- app/Notifications/WelcomingEmail.php | 58 ++++++++++++++++++++++++ app/Observers/UserObserver.php | 25 +++++----- app/Providers/EventServiceProvider.php | 5 +- resources/views/layout.blade.php | 10 +++- 6 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 app/Notifications/WelcomingEmail.php diff --git a/.env.example b/.env.example index 9c7a57e..e7e720b 100644 --- a/.env.example +++ b/.env.example @@ -23,7 +23,7 @@ REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 -MAIL_DRIVER=smtp +MAIL_DRIVER=log MAIL_HOST=smtp.mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index c65543f..13834e6 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -28,12 +28,10 @@ public function store( CreatingUserService $service ) { $user_saved = $service->execute($request->validated()); - if($user_saved){ - + if ($user_saved) { + return back()->with('success', 'Your account has been added!'); } - - - + return back()->with('error', 'Something went wrong, please try again later!'); } } diff --git a/app/Notifications/WelcomingEmail.php b/app/Notifications/WelcomingEmail.php new file mode 100644 index 0000000..6806e1e --- /dev/null +++ b/app/Notifications/WelcomingEmail.php @@ -0,0 +1,58 @@ +line('Welcome ' . $notifiable->name) + ->action('Hello',url('/')) + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) { + return [ + // + ]; + } + +} diff --git a/app/Observers/UserObserver.php b/app/Observers/UserObserver.php index 1a6619b..4cda2f9 100644 --- a/app/Observers/UserObserver.php +++ b/app/Observers/UserObserver.php @@ -2,19 +2,19 @@ namespace App\Observers; -use App\User; +use App\Models\User; +use App\Notifications\WelcomingEmail; + +class UserObserver { -class UserObserver -{ /** * Handle the user "created" event. * * @param \App\User $user * @return void */ - public function created(User $user) - { - // + public function created(User $user) { + $user->notify(new WelcomingEmail); } /** @@ -23,8 +23,7 @@ public function created(User $user) * @param \App\User $user * @return void */ - public function updated(User $user) - { + public function updated(User $user) { // } @@ -34,8 +33,7 @@ public function updated(User $user) * @param \App\User $user * @return void */ - public function deleted(User $user) - { + public function deleted(User $user) { // } @@ -45,8 +43,7 @@ public function deleted(User $user) * @param \App\User $user * @return void */ - public function restored(User $user) - { + public function restored(User $user) { // } @@ -56,8 +53,8 @@ public function restored(User $user) * @param \App\User $user * @return void */ - public function forceDeleted(User $user) - { + public function forceDeleted(User $user) { // } + } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 723a290..23a6a7b 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -6,6 +6,8 @@ use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Event; +use App\Models\User; +use App\Observers\UserObserver; class EventServiceProvider extends ServiceProvider { @@ -28,7 +30,6 @@ class EventServiceProvider extends ServiceProvider public function boot() { parent::boot(); - - // + User::observe(UserObserver::class); } } diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php index d215a41..5644bb3 100644 --- a/resources/views/layout.blade.php +++ b/resources/views/layout.blade.php @@ -55,7 +55,15 @@
- + @if(session()->has('success')) +
+ {{ session()->get('success') }} +
+ @elseif(session()->has('error')) +
+ {{ session()->get('error') }} +
+ @endif @yield('content') From 7af0e262ee541097be69a352a4d8b9112a3e9112 Mon Sep 17 00:00:00 2001 From: Aly Ragab Date: Sat, 22 Jan 2022 16:16:03 +0200 Subject: [PATCH 09/12] listing command --- app/Console/Commands/UsersList.php | 48 ++++++++++++++++++++++++++++ app/Notifications/WelcomingEmail.php | 1 - 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/UsersList.php diff --git a/app/Console/Commands/UsersList.php b/app/Console/Commands/UsersList.php new file mode 100644 index 0000000..b23fa01 --- /dev/null +++ b/app/Console/Commands/UsersList.php @@ -0,0 +1,48 @@ +toArray(); + if (count($data)) { + $this->table($headers, $data); + return; + } + $this->info("No users yet"); + } + +} diff --git a/app/Notifications/WelcomingEmail.php b/app/Notifications/WelcomingEmail.php index 6806e1e..ce9622f 100644 --- a/app/Notifications/WelcomingEmail.php +++ b/app/Notifications/WelcomingEmail.php @@ -39,7 +39,6 @@ public function via($notifiable) { public function toMail($notifiable) { return (new MailMessage) ->line('Welcome ' . $notifiable->name) - ->action('Hello',url('/')) ->line('Thank you for using our application!'); } From 2d3465a144bdfd0101e454a05700349096058ad2 Mon Sep 17 00:00:00 2001 From: Aly Ragab Date: Sat, 22 Jan 2022 16:24:50 +0200 Subject: [PATCH 10/12] move headers after checking data --- app/Console/Commands/UsersList.php | 4 ++-- app/Services/CreatingUserService.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/UsersList.php b/app/Console/Commands/UsersList.php index b23fa01..4913649 100644 --- a/app/Console/Commands/UsersList.php +++ b/app/Console/Commands/UsersList.php @@ -33,12 +33,12 @@ public function __construct() { /** * Execute the console command. * - * @return int + * @return */ public function handle() { - $headers = ['Name', 'Email', 'Postcode']; $data = User::get(['name', 'email', 'postcode'])->toArray(); if (count($data)) { + $headers = ['Name', 'Email', 'Postcode']; $this->table($headers, $data); return; } diff --git a/app/Services/CreatingUserService.php b/app/Services/CreatingUserService.php index a66feda..75f4728 100644 --- a/app/Services/CreatingUserService.php +++ b/app/Services/CreatingUserService.php @@ -14,6 +14,10 @@ class CreatingUserService { */ private $repo = null; + /** + * + * @param UsersRepositories $repo + */ public function __construct(UsersRepositories $repo) { $this->repo = $repo; } From 1c41eecd29db23c64cb6f725ee943647553356eb Mon Sep 17 00:00:00 2001 From: Aly Ragab Date: Sat, 22 Jan 2022 16:49:12 +0200 Subject: [PATCH 11/12] make command retuurn int --- app/Console/Commands/UsersList.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/UsersList.php b/app/Console/Commands/UsersList.php index 4913649..61cde6c 100644 --- a/app/Console/Commands/UsersList.php +++ b/app/Console/Commands/UsersList.php @@ -33,16 +33,17 @@ public function __construct() { /** * Execute the console command. * - * @return + * @return int */ public function handle() { $data = User::get(['name', 'email', 'postcode'])->toArray(); if (count($data)) { $headers = ['Name', 'Email', 'Postcode']; $this->table($headers, $data); - return; + } else { + $this->info("No users yet"); } - $this->info("No users yet"); + return 0; } } From 2d0168d32b632fc1b000ce682bbb12ee815c7fe2 Mon Sep 17 00:00:00 2001 From: Aly Ragab Date: Sat, 22 Jan 2022 17:55:16 +0200 Subject: [PATCH 12/12] remove unnecessary code & make email working on jobs --- .env.example | 2 +- app/Notifications/WelcomingEmail.php | 23 +---------- app/Observers/UserObserver.php | 40 ------------------- app/Rules/PostCode.php | 5 ++- .../2022_01_22_152702_create_jobs_table.php | 36 +++++++++++++++++ 5 files changed, 41 insertions(+), 65 deletions(-) create mode 100644 database/migrations/2022_01_22_152702_create_jobs_table.php diff --git a/.env.example b/.env.example index e7e720b..7343e90 100644 --- a/.env.example +++ b/.env.example @@ -15,7 +15,7 @@ DB_CONNECTION=mysql BROADCAST_DRIVER=log CACHE_DRIVER=file -QUEUE_CONNECTION=sync +QUEUE_CONNECTION=database SESSION_DRIVER=file SESSION_LIFETIME=120 diff --git a/app/Notifications/WelcomingEmail.php b/app/Notifications/WelcomingEmail.php index ce9622f..e267879 100644 --- a/app/Notifications/WelcomingEmail.php +++ b/app/Notifications/WelcomingEmail.php @@ -7,19 +7,10 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class WelcomingEmail extends Notification { +class WelcomingEmail extends Notification implements ShouldQueue { use Queueable; - /** - * Create a new notification instance. - * - * @return void - */ - public function __construct() { - // - } - /** * Get the notification's delivery channels. * @@ -42,16 +33,4 @@ public function toMail($notifiable) { ->line('Thank you for using our application!'); } - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) { - return [ - // - ]; - } - } diff --git a/app/Observers/UserObserver.php b/app/Observers/UserObserver.php index 4cda2f9..b9fb7ef 100644 --- a/app/Observers/UserObserver.php +++ b/app/Observers/UserObserver.php @@ -17,44 +17,4 @@ public function created(User $user) { $user->notify(new WelcomingEmail); } - /** - * Handle the user "updated" event. - * - * @param \App\User $user - * @return void - */ - public function updated(User $user) { - // - } - - /** - * Handle the user "deleted" event. - * - * @param \App\User $user - * @return void - */ - public function deleted(User $user) { - // - } - - /** - * Handle the user "restored" event. - * - * @param \App\User $user - * @return void - */ - public function restored(User $user) { - // - } - - /** - * Handle the user "force deleted" event. - * - * @param \App\User $user - * @return void - */ - public function forceDeleted(User $user) { - // - } - } diff --git a/app/Rules/PostCode.php b/app/Rules/PostCode.php index 45d8250..aca74d1 100644 --- a/app/Rules/PostCode.php +++ b/app/Rules/PostCode.php @@ -16,9 +16,10 @@ class PostCode implements Rule { public function passes($attribute, $value) { $response = guzzleGet( ['Content-Type' => 'application/json'], - getenv('POST_CODE_CHECK_URL') . $value + getenv('POST_CODE_CHECK_URL') . $value . '/validate' ); - return $response['status']; + + return $response['status'] ? $response['response']['result'] : false; } /** diff --git a/database/migrations/2022_01_22_152702_create_jobs_table.php b/database/migrations/2022_01_22_152702_create_jobs_table.php new file mode 100644 index 0000000..1be9e8a --- /dev/null +++ b/database/migrations/2022_01_22_152702_create_jobs_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('jobs'); + } +}