From b111f10ec8062185ac9ba75fab32b4ac85081e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Salvatori?= Date: Sat, 2 Mar 2024 20:11:59 -0500 Subject: [PATCH] Livewire Example added --- README.md | 4 +- app/Fields/ExtraLinks.php | 25 ++++ app/Livewire/AsyncQuery.php | 50 +++++++ app/setup.php | 4 + composer.json | 4 + composer.lock | 136 +++++++++++++++++- index.php | 6 - resources/scripts/routes/common.js | 3 +- resources/views/front-page.blade.php | 2 +- resources/views/layouts/app.blade.php | 7 + .../views/livewire/async-query.blade.php | 12 ++ 11 files changed, 241 insertions(+), 12 deletions(-) create mode 100644 app/Fields/ExtraLinks.php create mode 100644 app/Livewire/AsyncQuery.php create mode 100644 resources/views/livewire/async-query.blade.php diff --git a/README.md b/README.md index 2aa7faa..83212da 100644 --- a/README.md +++ b/README.md @@ -99,8 +99,8 @@ Add the following variables in your project `.env` HMR_ENABLED=true # Endpoint where the bundler serve your assets HMR_ENTRYPOINT=http://localhost:5173 -# Enable the Experimental Router for Laravel Routing -ACORN_ENABLE_EXPIRIMENTAL_ROUTER=true +# Add an APP_KEY for LiveWire +APP_KEY= #some 32 characters randomized string ``` #### Maintainance Mode diff --git a/app/Fields/ExtraLinks.php b/app/Fields/ExtraLinks.php new file mode 100644 index 0000000..8e74a09 --- /dev/null +++ b/app/Fields/ExtraLinks.php @@ -0,0 +1,25 @@ +setLocation('post_type', '==', 'post'); + + $extraLinks + ->addLink('external_link'); + + return $extraLinks->build(); + } +} diff --git a/app/Livewire/AsyncQuery.php b/app/Livewire/AsyncQuery.php new file mode 100644 index 0000000..0f98483 --- /dev/null +++ b/app/Livewire/AsyncQuery.php @@ -0,0 +1,50 @@ +posts[] = [ + 'title' => $post->post_title, + 'link' => get_field('external_link', $post->ID), + 'id' => $post->ID, + 'slug' => $post->post_name, + 'date' => $post->post_date, + 'content' => $post->post_content, + 'excerpt' => $post->post_excerpt, + 'status' => $post->post_status, + 'type' => $post->post_type, + 'author' => $post->post_author, + 'modified' => $post->post_modified, + 'modified_gmt' => $post->post_modified_gmt, + 'comment_status' => $post->comment_status, + 'comment_count' => $post->comment_count, + 'thumbnail' => get_the_post_thumbnail($post->ID, 'thumbnail') + ]; + } + } + } + + public function getPostsLinks(){ + $posts = get_posts(); + if($posts){ + foreach($posts as $post){ + $this->posts_links[] = get_field('external_link', $post->ID); + } + } + } + + public function render() + { + return view('livewire.async-query'); + } +} diff --git a/app/setup.php b/app/setup.php index 915d0d6..ce5c7ed 100644 --- a/app/setup.php +++ b/app/setup.php @@ -8,6 +8,9 @@ use function Roots\bundle; +// use Blade +use function Blade\Blade; + $directives = new \Log1x\SageDirectives\Directives(); $directives_util = new \Log1x\SageDirectives\Util(); @@ -160,6 +163,7 @@ * @see app/medias.php */ set_image_sizes(); + }, 20); /** diff --git a/composer.json b/composer.json index 0ab144a..7374fc0 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,11 @@ "require": { "php": "^8.2", "generoi/sage-woocommerce": "^1.1.2", + "illuminate/encryption": "^10.46", + "illuminate/queue": "^10.46", "illuminate/support": "^10.33", + "illuminate/testing": "^10.46", + "livewire/livewire": "^3.4", "log1x/acf-composer": "^3.0.20", "log1x/pagi": "^1.0", "log1x/poet": "^2.0", diff --git a/composer.lock b/composer.lock index 8029337..9a0d235 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": "7bda4711adeac1c21751d784bf1da65f", + "content-hash": "d1c0f65689e7138e5c4f59e15abcaf13", "packages": [ { "name": "brick/math", @@ -1820,6 +1820,65 @@ }, "time": "2024-02-26T22:20:06+00:00" }, + { + "name": "illuminate/testing", + "version": "v10.46.0", + "source": { + "type": "git", + "url": "https://github.com/illuminate/testing.git", + "reference": "5e5f0d8a30cae66f8383098bee623cc75b60af8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/testing/zipball/5e5f0d8a30cae66f8383098bee623cc75b60af8c", + "reference": "5e5f0d8a30cae66f8383098bee623cc75b60af8c", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "illuminate/collections": "^10.0", + "illuminate/contracts": "^10.0", + "illuminate/macroable": "^10.0", + "illuminate/support": "^10.0", + "php": "^8.1" + }, + "suggest": { + "brianium/paratest": "Required to run tests in parallel (^6.0).", + "illuminate/console": "Required to assert console commands (^10.0).", + "illuminate/database": "Required to assert databases (^10.0).", + "illuminate/http": "Required to assert responses (^10.0).", + "mockery/mockery": "Required to use mocking (^1.5.1).", + "phpunit/phpunit": "Required to use assertions and run tests (^9.5.8|^10.0.7)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "10.x-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Testing\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Testing package.", + "homepage": "https://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "time": "2024-02-08T15:10:07+00:00" + }, { "name": "illuminate/translation", "version": "v10.46.0", @@ -2490,6 +2549,81 @@ ], "time": "2024-01-28T23:22:08+00:00" }, + { + "name": "livewire/livewire", + "version": "v3.4.6", + "source": { + "type": "git", + "url": "https://github.com/livewire/livewire.git", + "reference": "7e7d638183b34fb61621455891869f5abfd55a82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/livewire/livewire/zipball/7e7d638183b34fb61621455891869f5abfd55a82", + "reference": "7e7d638183b34fb61621455891869f5abfd55a82", + "shasum": "" + }, + "require": { + "illuminate/database": "^10.0|^11.0", + "illuminate/routing": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", + "illuminate/validation": "^10.0|^11.0", + "league/mime-type-detection": "^1.9", + "php": "^8.1", + "symfony/http-kernel": "^6.2|^7.0" + }, + "require-dev": { + "calebporzio/sushi": "^2.1", + "laravel/framework": "^10.0|^11.0", + "laravel/prompts": "^0.1.6", + "mockery/mockery": "^1.3.1", + "orchestra/testbench": "8.20.0|^9.0", + "orchestra/testbench-dusk": "8.20.0|^9.0", + "phpunit/phpunit": "^10.4", + "psy/psysh": "^0.11.22|^0.12" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Livewire\\LivewireServiceProvider" + ], + "aliases": { + "Livewire": "Livewire\\Livewire" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Livewire\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Caleb Porzio", + "email": "calebporzio@gmail.com" + } + ], + "description": "A front-end framework for Laravel.", + "support": { + "issues": "https://github.com/livewire/livewire/issues", + "source": "https://github.com/livewire/livewire/tree/v3.4.6" + }, + "funding": [ + { + "url": "https://github.com/livewire", + "type": "github" + } + ], + "time": "2024-02-20T14:04:25+00:00" + }, { "name": "log1x/acf-composer", "version": "v3.0.20", diff --git a/index.php b/index.php index 4fa1196..d34cf55 100644 --- a/index.php +++ b/index.php @@ -1,12 +1,6 @@ > - - - - - - render(); ?> diff --git a/resources/scripts/routes/common.js b/resources/scripts/routes/common.js index 5d920c2..4a27f5f 100644 --- a/resources/scripts/routes/common.js +++ b/resources/scripts/routes/common.js @@ -1,5 +1,4 @@ -import 'alpine-magic-helpers'; //@Alpine Extensionr: https://www.alpinetoolbox.com/extensions/ -import Alpine from 'alpinejs'; +//import Alpine from 'alpinejs'; import { Transitions } from '../transitions'; import { diff --git a/resources/views/front-page.blade.php b/resources/views/front-page.blade.php index 2601f34..a279769 100644 --- a/resources/views/front-page.blade.php +++ b/resources/views/front-page.blade.php @@ -8,7 +8,7 @@ 'tags' => ['Amsterdam'], 'category' => '', ]) - +@livewire('async_query') @if(function_exists('get_field')) @include('partials.billboard-list', [ 'billboards' => get_field('billboards_section_1', 81) diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index b426933..e56a109 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -1,3 +1,9 @@ + + + + + @livewireStyles + > @@ -21,4 +27,5 @@ + @livewireScripts diff --git a/resources/views/livewire/async-query.blade.php b/resources/views/livewire/async-query.blade.php new file mode 100644 index 0000000..eed7623 --- /dev/null +++ b/resources/views/livewire/async-query.blade.php @@ -0,0 +1,12 @@ +
+
Posts
+
+        {{print_r($posts)}}
+    
+
Posts external links
+
+        {{print_r($posts_links)}}
+    
+
get posts
+
get posts external links
+