diff --git a/app/Http/Controllers/InertiaMinimal/RecipeController.php b/app/Http/Controllers/InertiaMinimal/RecipeController.php new file mode 100644 index 0000000..e0cecc5 --- /dev/null +++ b/app/Http/Controllers/InertiaMinimal/RecipeController.php @@ -0,0 +1,82 @@ + Recipe::query() + ->paginate(12) + ->through(fn($recipe) => [ + 'id' => $recipe->id, + 'title' => $recipe->title, + 'slug' => $recipe->slug, + 'image' => $recipe->getFirstMediaUrl('recipe_image', 'card'), + ]), + ]); + } + + /** + * Display the specified resource. + * + * @param \Illuminate\Http\Request $request + * @param string $slug + * @return \Inertia\Response + */ + public function show(Request $request, string $slug) + { + $recipe = Recipe::findBySlug($slug); + + return Inertia::render('Recipes/Show', [ + 'recipe' => [ + 'id' => $recipe->id, + 'title' => $recipe->title, + 'slug' => $recipe->slug, + 'image' => $recipe->getFirstMediaUrl('recipe_image', 'show'), + 'summary' => $recipe->summary, + 'tags' => $recipe->tags->pluck('name'), + 'servings' => $recipe->servings, + 'preparation_minutes' => $recipe->preparation_minutes, + 'cooking_minutes' => $recipe->cooking_minutes, + 'difficulty' => Str::ucfirst(__('recipes.' . $recipe->difficulty)), + 'ingredients' => new IngredientsResource($recipe->ingredients), + 'instructions' => $recipe->instructions, + 'source_label' => $recipe->source_label, + 'source_link' => $recipe->source_link, + 'created_at' => $recipe->created_at, + 'structured_data' => [ + 'description' => strip_tags($recipe->summary), + 'ingredients' => new StructuredDataIngredientsResource($recipe->ingredients), + 'instructions' => new InstructionsResource($recipe->instructions), + 'keywords' => implode(',', $recipe->tags->pluck('name')->toArray()), + ], + ], + ])->withViewData([ + 'open_graph' => [ + 'title' => $recipe->title, + 'image' => $recipe->getFirstMediaUrl('recipe_image', 'show'), + 'url' => URL::current(), + ], + ]); + } +} diff --git a/app/Http/Middleware/Inertia/HandleInertiaMinimalRequests.php b/app/Http/Middleware/Inertia/HandleInertiaMinimalRequests.php new file mode 100644 index 0000000..8b4cdf8 --- /dev/null +++ b/app/Http/Middleware/Inertia/HandleInertiaMinimalRequests.php @@ -0,0 +1,53 @@ + [ + 'user' => $request->user(), + ], + 'flash' => [ + 'error' => fn() => $request->session()->get('error'), + 'success' => fn() => $request->session()->get('success'), + 'warning' => fn() => $request->session()->get('warning'), + ], + 'ziggy' => function () use ($request) { + return array_merge((new Ziggy)->toArray(), [ + 'location' => $request->url(), + ]); + }, + ]); + } +} diff --git a/resources/js/InertiaMinimal/Components/Pagination.vue b/resources/js/InertiaMinimal/Components/Pagination.vue new file mode 100644 index 0000000..d4ba623 --- /dev/null +++ b/resources/js/InertiaMinimal/Components/Pagination.vue @@ -0,0 +1,25 @@ + + + diff --git a/resources/js/InertiaMinimal/Components/RecipeCard.vue b/resources/js/InertiaMinimal/Components/RecipeCard.vue new file mode 100644 index 0000000..2a0e8e0 --- /dev/null +++ b/resources/js/InertiaMinimal/Components/RecipeCard.vue @@ -0,0 +1,24 @@ + + diff --git a/resources/js/InertiaMinimal/Layouts/Default.vue b/resources/js/InertiaMinimal/Layouts/Default.vue new file mode 100644 index 0000000..c36ed5d --- /dev/null +++ b/resources/js/InertiaMinimal/Layouts/Default.vue @@ -0,0 +1,5 @@ + diff --git a/resources/js/InertiaMinimal/Pages/Recipes/Index.vue b/resources/js/InertiaMinimal/Pages/Recipes/Index.vue new file mode 100644 index 0000000..072d348 --- /dev/null +++ b/resources/js/InertiaMinimal/Pages/Recipes/Index.vue @@ -0,0 +1,28 @@ + + + diff --git a/resources/js/InertiaMinimal/Pages/Recipes/Show.vue b/resources/js/InertiaMinimal/Pages/Recipes/Show.vue new file mode 100644 index 0000000..7384521 --- /dev/null +++ b/resources/js/InertiaMinimal/Pages/Recipes/Show.vue @@ -0,0 +1,210 @@ + + + diff --git a/resources/js/InertiaMinimal/app.js b/resources/js/InertiaMinimal/app.js new file mode 100644 index 0000000..66d18d8 --- /dev/null +++ b/resources/js/InertiaMinimal/app.js @@ -0,0 +1,30 @@ +import "../bootstrap"; +import "../../scss/app.scss"; + +import CKEditor from "@ckeditor/ckeditor5-vue"; +import { createInertiaApp } from "@inertiajs/vue3"; +import { resolvePageComponent } from "laravel-vite-plugin/inertia-helpers"; +import { createApp, h } from "vue"; +import { ZiggyVue } from "../../../vendor/tightenco/ziggy/dist/vue.m"; + +const appName = window.document.getElementsByTagName("title")[0]?.innerText || "Koken met Marc"; + +createInertiaApp({ + title: (title) => { + if (title) { + return `${title} - ${appName}`; + } + return `${appName}`; + }, + resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob("./Pages/**/*.vue")), + setup({ el, App, props, plugin }) { + return createApp({ render: () => h(App, props) }) + .use(plugin) + .use(ZiggyVue) + .use(CKEditor) + .mount(el); + }, + progress: { + color: "#4B5563", + }, +}); diff --git a/resources/views/inertia-minimal/app.blade.php b/resources/views/inertia-minimal/app.blade.php new file mode 100644 index 0000000..3ed05bc --- /dev/null +++ b/resources/views/inertia-minimal/app.blade.php @@ -0,0 +1,11 @@ +@extends("inertia-minimal.layout") + +@section("head") + @routes + @vite("resources/js/InertiaMinimal/app.js") + @inertiaHead +@endsection + +@section("content") + @inertia +@endsection diff --git a/resources/views/inertia-minimal/layout.blade.php b/resources/views/inertia-minimal/layout.blade.php new file mode 100644 index 0000000..c2d4fee --- /dev/null +++ b/resources/views/inertia-minimal/layout.blade.php @@ -0,0 +1,28 @@ + +getLocale()) }}"> + + + + + @section("title") + {{ config("app.name", "Laravel") }} + @endsection + + + + + + + + + + + + + + @yield("head") + + + @yield("content") + + diff --git a/routes/web.php b/routes/web.php index 83d99a0..31dd3e6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Inertia\SearchController; use App\Http\Controllers\Inertia\User\ChangePasswordController; use App\Http\Controllers\Inertia\User\UserController; +use App\Http\Controllers\InertiaMinimal\RecipeController as InertiaMinimalRecipeController; use Illuminate\Support\Facades\Route; /* @@ -65,3 +66,13 @@ Route::get('/blade/{slug}', [BladeRecipeController::class, 'show'])->name('blade.show'); // END Blade routes + +// START Inertia Minimal routes + +Route::middleware([\App\Http\Middleware\Inertia\HandleInertiaMinimalRequests::class]) + ->withoutMiddleware([\App\Http\Middleware\Inertia\HandleInertiaRequests::class]) + ->group(function () { + Route::get('/inertia-minimal', [InertiaMinimalRecipeController::class, 'index'])->name('inertia-minimal.home'); + Route::get('/inertia-minimal/{slug}', [InertiaMinimalRecipeController::class, 'show'])->name('inertia-minimal.show'); + }); +// END Inertia Minimal routes diff --git a/vite.config.js b/vite.config.js index e7e8346..6dd5dbc 100644 --- a/vite.config.js +++ b/vite.config.js @@ -15,6 +15,8 @@ export default defineConfig({ "resources/scss/app.scss", // For the Inertia app "resources/js/Inertia/app.js", + // For the InertiaMinimal app + "resources/js/InertiaMinimal/app.js", ], refresh: true, }),