From eb0a8f767c4cff4c7588fcaedd375c7cc23f7ed4 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Mon, 11 Oct 2021 22:18:49 +0200 Subject: [PATCH 1/4] Update middleware for api --- app/Providers/RouteServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 194b1f8ec..e9661b64f 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -39,7 +39,7 @@ public function boot() $this->routes(function () { Route::prefix('api') - ->middleware('api') + ->middleware(['api', 'auth:sanctum']) ->namespace($this->namespace) ->group(base_path('routes/api.php')); From 5347491167d4ff649f297a787b7a72f56f2070cd Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Mon, 11 Oct 2021 22:19:05 +0200 Subject: [PATCH 2/4] Added pretty routes --- composer.json | 3 +- composer.lock | 131 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dca4a65fa..e8542f80f 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "spatie/laravel-activitylog": "^3.16", "spatie/laravel-cookie-consent": "^2.12", "spatie/laravel-permission": "^4.2", - "spatie/laravel-tags": "^3.1" + "spatie/laravel-tags": "^3.1", + "wulfheart/pretty_routes": "^0.3.0" }, "require-dev": { "barryvdh/laravel-debugbar": "^3.5", diff --git a/composer.lock b/composer.lock index 167b52db1..e9dfa0984 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": "7066f66daa34c25894f7031d26baeace", + "content-hash": "44c1fad76753f75894da853fdd1cead2", "packages": [ { "name": "anlutro/l4-settings", @@ -6765,6 +6765,66 @@ ], "time": "2021-02-26T08:04:10+00:00" }, + { + "name": "spatie/laravel-package-tools", + "version": "1.9.2", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-package-tools.git", + "reference": "f710fe196c126fb9e0aee67eb5af49ad8f13f528" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/f710fe196c126fb9e0aee67eb5af49ad8f13f528", + "reference": "f710fe196c126fb9e0aee67eb5af49ad8f13f528", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^7.0|^8.0", + "php": "^7.4|^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.4", + "orchestra/testbench": "^5.0|^6.0", + "phpunit/phpunit": "^9.3", + "spatie/test-time": "^1.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\LaravelPackageTools\\": "src", + "Spatie\\LaravelPackageTools\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Tools for creating Laravel packages", + "homepage": "https://github.com/spatie/laravel-package-tools", + "keywords": [ + "laravel-package-tools", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-package-tools/issues", + "source": "https://github.com/spatie/laravel-package-tools/tree/1.9.2" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2021-09-21T13:06:51+00:00" + }, { "name": "spatie/laravel-permission", "version": "4.4.1", @@ -10048,6 +10108,75 @@ "source": "https://github.com/webmozarts/assert/tree/1.10.0" }, "time": "2021-03-09T10:59:23+00:00" + }, + { + "name": "wulfheart/pretty_routes", + "version": "0.3.0", + "source": { + "type": "git", + "url": "https://github.com/Wulfheart/pretty-routes.git", + "reference": "e257fac400db2c696ddaec197e634b1fc7c40d22" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Wulfheart/pretty-routes/zipball/e257fac400db2c696ddaec197e634b1fc7c40d22", + "reference": "e257fac400db2c696ddaec197e634b1fc7c40d22", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^8.0", + "php": "^7.4|^8.0", + "spatie/laravel-package-tools": "^1.4.3" + }, + "require-dev": { + "brianium/paratest": "^6.2", + "nunomaduro/collision": "^5.3", + "orchestra/testbench": "^6.15", + "phpunit/phpunit": "^9.3", + "spatie/laravel-ray": "^1.9", + "spatie/phpunit-snapshot-assertions": "^4.2", + "vimeo/psalm": "^4.4" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Wulfheart\\PrettyRoutes\\PrettyRoutesServiceProvider" + ], + "aliases": { + "PrettyRoutes": "Wulfheart\\PrettyRoutes\\PrettyRoutesFacade" + } + } + }, + "autoload": { + "psr-4": { + "Wulfheart\\PrettyRoutes\\": "src", + "Wulfheart\\PrettyRoutes\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alexander Wulf", + "email": "dev@alexfwulf.de", + "role": "Developer" + } + ], + "description": "Display your Laravel routes in the console, but make it pretty. 😎", + "homepage": "https://github.com/wulfheart/pretty_routes", + "keywords": [ + "laravel", + "pretty_routes", + "wulfheart" + ], + "support": { + "issues": "https://github.com/Wulfheart/pretty-routes/issues", + "source": "https://github.com/Wulfheart/pretty-routes/tree/0.3.0" + }, + "time": "2021-05-03T09:19:08+00:00" } ], "packages-dev": [ From c4117fff279cedf82f4a0aca8c25494a24aefdef Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Mon, 11 Oct 2021 22:19:11 +0200 Subject: [PATCH 3/4] Create UserResource.php --- app/Http/Resources/UserResource.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/Http/Resources/UserResource.php diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php new file mode 100644 index 000000000..7a745492e --- /dev/null +++ b/app/Http/Resources/UserResource.php @@ -0,0 +1,19 @@ + Date: Mon, 11 Oct 2021 22:19:51 +0200 Subject: [PATCH 4/4] Added WIP user api endpoint --- app/Http/Controllers/API/UserController.php | 81 +++++++++++++++++++++ routes/api.php | 6 +- 2 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 app/Http/Controllers/API/UserController.php diff --git a/app/Http/Controllers/API/UserController.php b/app/Http/Controllers/API/UserController.php new file mode 100644 index 000000000..0bbd7f82b --- /dev/null +++ b/app/Http/Controllers/API/UserController.php @@ -0,0 +1,81 @@ +middleware(['permission:api']); + } + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function index() + { + // + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function show(Request $request, $id) + { + $user = User::with(['roles.permissions'])->findOrFail($id); + if (!$request->user()->tokenCan('read')) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } + if ($request->user()->id !== $user->id) { + return response()->json([ + 'error' => 'You are not allowed to view this user!', + ]); + } + return new UserResource($user); + } + + /** + * 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/routes/api.php b/routes/api.php index eb6fa48c2..0c5ddca27 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,6 @@ get('/user', function (Request $request) { - return $request->user(); -}); +Route::apiResource('user', UserController::class); \ No newline at end of file