diff --git a/app/Http/Middleware/CheckApiErrors.php b/app/Http/Middleware/CheckApiErrors.php new file mode 100644 index 0000000..01b0d79 --- /dev/null +++ b/app/Http/Middleware/CheckApiErrors.php @@ -0,0 +1,30 @@ +exception) { + $error = $response->exception; + + if ($error->getCode() === 401) { + Session::forget('token'); + return redirect()->route('login')->with('error', 'Session expired. Please login again.'); + } elseif ($error->getCode() === 404) { + return redirect('/404'); + } else { + return redirect()->back()->with('error', $error->getMessage()); + } + } + + return $response; + } +} \ No newline at end of file diff --git a/app/Livewire/ErrorHandler.php b/app/Livewire/ErrorHandler.php new file mode 100644 index 0000000..ee03a86 --- /dev/null +++ b/app/Livewire/ErrorHandler.php @@ -0,0 +1,26 @@ +route('login')->with('error', 'Session expired. Please login again. ' . ($message ? '- ' . $message : '')); + } elseif ($status == 404) { + return redirect('/404')->with('error', 'Page not found.'); + } else { + Session::flash('error', 'Something went wrong! ' . ($message ? '- ' . $message : '')); + } + } + + public function render() + { + return view('livewire.error-handler'); + } +} \ No newline at end of file diff --git a/app/Livewire/FetchData.php b/app/Livewire/FetchData.php new file mode 100644 index 0000000..8f135b9 --- /dev/null +++ b/app/Livewire/FetchData.php @@ -0,0 +1,44 @@ +url = $url; + $this->fetchData(); + } + + public function fetchData() + { + $this->loading = true; + + try { + $response = Http::get(config('app.api_base_url') . $this->url); + + if ($response->successful()) { + $this->data = $response->json(); + } else { + Session::flash('error', 'Failed to fetch data: ' . $response->body()); + } + } catch (\Exception $e) { + Session::flash('error', 'An error occurred while fetching data.'); + } finally { + $this->loading = false; + } + } + + public function render() + { + return view('livewire.fetch-data'); + } +} \ No newline at end of file diff --git a/app/Livewire/Logout.php b/app/Livewire/Logout.php new file mode 100644 index 0000000..9d1403c --- /dev/null +++ b/app/Livewire/Logout.php @@ -0,0 +1,27 @@ + 'Bearer ' . Session::get('token')])->get(config('app.api_base_url') . '/logout'); + + Session::forget('token'); + return redirect()->route('login')->with('success', 'Logged out successfully.'); + } catch (\Exception $e) { + return redirect()->back()->with('error', 'Logout failed: ' . $e->getMessage()); + } + } + + public function render() + { + return view('livewire.logout'); + } +} \ No newline at end of file diff --git a/bootstrap/app.php b/bootstrap/app.php index 7b162da..1edf064 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Configuration\Middleware; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', + commands: __DIR__.'/../routes/console.php', health: '/up', ) diff --git a/composer.json b/composer.json index c02d127..16901e0 100644 --- a/composer.json +++ b/composer.json @@ -7,12 +7,15 @@ "license": "MIT", "require": { "php": "^8.2", + "guzzlehttp/guzzle": "^7.9", "laravel/framework": "^11.31", "laravel/tinker": "^2.9", + "laravel/ui": "^4.6", "livewire/livewire": "^3.6" }, "require-dev": { "fakerphp/faker": "^1.23", + "laravel/breeze": "^2.3", "laravel/pail": "^1.1", "laravel/pint": "^1.13", "laravel/sail": "^1.26", diff --git a/composer.lock b/composer.lock index b33c127..b33b6bf 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": "3f2b8489b8613c8a63271dd2fed1a745", + "content-hash": "285c8ee44334e3e198f19e9bd78c85e5", "packages": [ { "name": "brick/math", @@ -1455,6 +1455,69 @@ }, "time": "2025-01-27T14:24:01+00:00" }, + { + "name": "laravel/ui", + "version": "v4.6.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/ui.git", + "reference": "7d6ffa38d79f19c9b3e70a751a9af845e8f41d88" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/ui/zipball/7d6ffa38d79f19c9b3e70a751a9af845e8f41d88", + "reference": "7d6ffa38d79f19c9b3e70a751a9af845e8f41d88", + "shasum": "" + }, + "require": { + "illuminate/console": "^9.21|^10.0|^11.0|^12.0", + "illuminate/filesystem": "^9.21|^10.0|^11.0|^12.0", + "illuminate/support": "^9.21|^10.0|^11.0|^12.0", + "illuminate/validation": "^9.21|^10.0|^11.0|^12.0", + "php": "^8.0", + "symfony/console": "^6.0|^7.0" + }, + "require-dev": { + "orchestra/testbench": "^7.35|^8.15|^9.0|^10.0", + "phpunit/phpunit": "^9.3|^10.4|^11.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laravel\\Ui\\UiServiceProvider" + ] + }, + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Laravel\\Ui\\": "src/", + "Illuminate\\Foundation\\Auth\\": "auth-backend/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel UI utilities and presets.", + "keywords": [ + "laravel", + "ui" + ], + "support": { + "source": "https://github.com/laravel/ui/tree/v4.6.1" + }, + "time": "2025-01-28T15:15:29+00:00" + }, { "name": "league/commonmark", "version": "2.6.1", @@ -6048,6 +6111,67 @@ }, "time": "2020-07-09T08:09:16+00:00" }, + { + "name": "laravel/breeze", + "version": "v2.3.6", + "source": { + "type": "git", + "url": "https://github.com/laravel/breeze.git", + "reference": "390cbc433cb72fa6050965000b2d56c9ba6fd713" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/breeze/zipball/390cbc433cb72fa6050965000b2d56c9ba6fd713", + "reference": "390cbc433cb72fa6050965000b2d56c9ba6fd713", + "shasum": "" + }, + "require": { + "illuminate/console": "^11.0|^12.0", + "illuminate/filesystem": "^11.0|^12.0", + "illuminate/support": "^11.0|^12.0", + "illuminate/validation": "^11.0|^12.0", + "php": "^8.2.0", + "symfony/console": "^7.0" + }, + "require-dev": { + "laravel/framework": "^11.0|^12.0", + "orchestra/testbench-core": "^9.0|^10.0", + "phpstan/phpstan": "^2.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laravel\\Breeze\\BreezeServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Breeze\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Minimal Laravel authentication scaffolding with Blade and Tailwind.", + "keywords": [ + "auth", + "laravel" + ], + "support": { + "issues": "https://github.com/laravel/breeze/issues", + "source": "https://github.com/laravel/breeze" + }, + "time": "2025-03-06T14:02:32+00:00" + }, { "name": "laravel/pail", "version": "v1.2.2", diff --git a/package-lock.json b/package-lock.json index 1cdb776..11fc1d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,8 @@ "": { "dependencies": { "bootstrap": "^5.3.5", - "bootstrap-icons": "^1.11.3" + "bootstrap-icons": "^1.11.3", + "sweetalert2": "^11.17.2" }, "devDependencies": { "autoprefixer": "^10.4.20", @@ -2579,6 +2580,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sweetalert2": { + "version": "11.17.2", + "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.17.2.tgz", + "integrity": "sha512-HKxDr1IyV3Lxr3W6sb61qm/p2epFIEdr5EKwteRFHnIg6f8nHFl2kX++DBVz16Mac+fFiU3hMpjq1L6yE2Ge5w==", + "funding": { + "type": "individual", + "url": "https://github.com/sponsors/limonte" + } + }, "node_modules/tailwindcss": { "version": "3.4.17", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz", diff --git a/package.json b/package.json index fe00332..1513274 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ }, "dependencies": { "bootstrap": "^5.3.5", - "bootstrap-icons": "^1.11.3" + "bootstrap-icons": "^1.11.3", + "sweetalert2": "^11.17.2" } } diff --git a/resources/css/app.css b/resources/css/app.css index b5c61c9..32d4f96 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -1,3 +1,4 @@ @tailwind base; @tailwind components; @tailwind utilities; +@import 'bootstrap/dist/css/bootstrap.min.css'; diff --git a/resources/js/app.js b/resources/js/app.js index e59d6a0..fd8be9f 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1 +1,3 @@ import './bootstrap'; +import 'bootstrap/dist/js/bootstrap.bundle.min.js'; +import 'sweetalert2/dist/sweetalert2.min.js'; diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php new file mode 100644 index 0000000..8c88540 --- /dev/null +++ b/resources/views/errors/404.blade.php @@ -0,0 +1,5 @@ +@extends('layouts.app') + +@section('content') +