Skip to content

Commit

Permalink
Livewire Example added
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansalvatori committed Mar 3, 2024
1 parent 7957d76 commit b111f10
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions app/Fields/ExtraLinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Fields;

use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Field;

class ExtraLinks extends Field
{
/**
* The field group.
*/
public function fields(): array
{
$extraLinks = Builder::make('extra_links');

$extraLinks
->setLocation('post_type', '==', 'post');

$extraLinks
->addLink('external_link');

return $extraLinks->build();
}
}
50 changes: 50 additions & 0 deletions app/Livewire/AsyncQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Livewire;

use Livewire\Component;

class AsyncQuery extends Component
{
public $posts = [];
public $posts_links = [];

public function getPosts(){
$posts = get_posts();
if($posts){
foreach($posts as $post){
$this->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');
}
}
4 changes: 4 additions & 0 deletions app/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -160,6 +163,7 @@
* @see app/medias.php
*/
set_image_sizes();

}, 20);

/**
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
136 changes: 135 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<!doctype html>
<html <?php language_attributes(); ?>>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>

<?php echo view(app('sage.view'), app('sage.data'))->render(); ?>

</html>
3 changes: 1 addition & 2 deletions resources/scripts/routes/common.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion resources/views/front-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
@livewireStyles
</head>
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
<?php do_action('get_header'); ?>
Expand All @@ -21,4 +27,5 @@

<?php do_action('get_footer'); ?>
<?php wp_footer(); ?>
@livewireScripts
</body>
12 changes: 12 additions & 0 deletions resources/views/livewire/async-query.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div>
<div class="title">Posts</div>
<pre>
{{print_r($posts)}}
</pre>
<div class="title">Posts external links</div>
<pre>
{{print_r($posts_links)}}
</pre>
<div class="button is-primary" wire:click="getPosts">get posts</div>
<div class="button is-dark" wire:click="getPostsLinks">get posts external links</div>
</div>

0 comments on commit b111f10

Please sign in to comment.