Skip to content

Commit 4b98bcb

Browse files
committed
Initial commit
A working demo of AND and OR logic when querying Taxonomy Terms in a custom Tag. Signed-off-by: Marty Friedel <[email protected]>
0 parents  commit 4b98bcb

File tree

143 files changed

+38553
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+38553
-0
lines changed

Diff for: .editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

Diff for: .env.example

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
APP_NAME=Statamic
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
STATAMIC_LICENSE_KEY=
8+
STATAMIC_STACHE_WATCHER=true
9+
STATAMIC_STATIC_CACHING_STRATEGY=null
10+
STATAMIC_REVISIONS_ENABLED=false
11+
STATAMIC_GRAPHQL_ENABLED=false
12+
STATAMIC_API_ENABLED=false
13+
STATAMIC_GIT_ENABLED=false
14+
15+
LOG_CHANNEL=stack
16+
17+
DB_CONNECTION=mysql
18+
DB_HOST=127.0.0.1
19+
DB_PORT=3306
20+
DB_DATABASE=laravel
21+
DB_USERNAME=root
22+
DB_PASSWORD=
23+
24+
BROADCAST_DRIVER=log
25+
CACHE_DRIVER=file
26+
QUEUE_CONNECTION=sync
27+
SESSION_DRIVER=file
28+
SESSION_LIFETIME=120
29+
30+
REDIS_HOST=127.0.0.1
31+
REDIS_PASSWORD=null
32+
REDIS_PORT=6379
33+
34+
MAIL_MAILER=smtp
35+
MAIL_HOST=smtp.mailtrap.io
36+
MAIL_PORT=2525
37+
MAIL_USERNAME=null
38+
MAIL_PASSWORD=null
39+
MAIL_ENCRYPTION=null
40+
MAIL_FROM_ADDRESS=null
41+
MAIL_FROM_NAME="${APP_NAME}"
42+
43+
PUSHER_APP_ID=
44+
PUSHER_APP_KEY=
45+
PUSHER_APP_SECRET=
46+
PUSHER_APP_CLUSTER=mt1
47+
48+
AWS_ACCESS_KEY_ID=
49+
AWS_SECRET_ACCESS_KEY=
50+
AWS_DEFAULT_REGION=us-east-1
51+
AWS_BUCKET=
52+
53+
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
54+
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
55+
56+
DEBUGBAR_ENABLED=false

Diff for: .gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

Diff for: .github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: statamic

Diff for: .gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/node_modules
2+
/public/hot
3+
/public/storage
4+
/public/vendor/statamic
5+
/storage/*.key
6+
/vendor
7+
.env
8+
.env.backup
9+
.phpunit.result.cache
10+
.php_cs.cache
11+
/.idea/*
12+
Homestead.json
13+
Homestead.yaml
14+
npm-debug.log
15+
yarn-error.log
16+
.DS_Store

Diff for: .styleci.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
php:
2+
preset: laravel
3+
disabled:
4+
- no_unused_imports
5+
finder:
6+
not-name:
7+
- index.php
8+
- server.php
9+
js:
10+
finder:
11+
not-name:
12+
- webpack.mix.js
13+
css: true

Diff for: README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Demo of AND and OR logic when working with Taxonomies in Statamic 3
2+
3+
![Statamic 3.0+](https://img.shields.io/badge/Statamic-3.0+-FF269E?style=for-the-badge&link=https://statamic.com)
4+
5+
Sometimes you need greater flexibility and control when filtering a collection based on a taxonomy (or even multiple
6+
taxonomies).
7+
8+
Within your own tag, it is easy to build your own query using Statamic's EntryQueryBuilder that can perform different
9+
query logic (AND or OR) on your taxonomies to determine whether your filters become stricter (AND) or broader (OR).
10+
11+
For more information, check out my [filtering entries by Taxonomy in Statamic 3 using AND or OR logic](https://www.martyfriedel.com/blog/filtering-entries-by-taxonomy-in-statamic-3-using-and-or-logic).
12+
13+
## Run the demo
14+
15+
If you're reading this, you're probably already in the Statamic and/or Laravel way of thinking, so this should be
16+
straight forward.
17+
18+
1. Clone the repo, and configure your server as you normally would
19+
2. Create and configure your `.env` as necessary
20+
3. Run `composer install`
21+
4. Run `npm install`
22+
5. Build the assets with `npm run production`
23+
6. If you want to log in to the Control Panel, make yourself a user with `php please make:user`
24+
25+
## License
26+
27+
This addon is licensed under the MIT license.

Diff for: app/Console/Kernel.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
//
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
// $schedule->command('inspire')
28+
// ->hourly();
29+
}
30+
31+
/**
32+
* Register the commands for the application.
33+
*
34+
* @return void
35+
*/
36+
protected function commands()
37+
{
38+
$this->load(__DIR__.'/Commands');
39+
40+
require base_path('routes/console.php');
41+
}
42+
}

Diff for: app/Exceptions/Handler.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
6+
7+
class Handler extends ExceptionHandler
8+
{
9+
/**
10+
* A list of the exception types that are not reported.
11+
*
12+
* @var array
13+
*/
14+
protected $dontReport = [
15+
//
16+
];
17+
18+
/**
19+
* A list of the inputs that are never flashed for validation exceptions.
20+
*
21+
* @var array
22+
*/
23+
protected $dontFlash = [
24+
'password',
25+
'password_confirmation',
26+
];
27+
28+
/**
29+
* Register the exception handling callbacks for the application.
30+
*
31+
* @return void
32+
*/
33+
public function register()
34+
{
35+
//
36+
}
37+
}

Diff for: app/Http/Controllers/Controller.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
6+
use Illuminate\Foundation\Bus\DispatchesJobs;
7+
use Illuminate\Foundation\Validation\ValidatesRequests;
8+
use Illuminate\Routing\Controller as BaseController;
9+
10+
class Controller extends BaseController
11+
{
12+
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
13+
}

Diff for: app/Http/Kernel.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace App\Http;
4+
5+
use Illuminate\Foundation\Http\Kernel as HttpKernel;
6+
7+
class Kernel extends HttpKernel
8+
{
9+
/**
10+
* The application's global HTTP middleware stack.
11+
*
12+
* These middleware are run during every request to your application.
13+
*
14+
* @var array
15+
*/
16+
protected $middleware = [
17+
\App\Http\Middleware\TrustProxies::class,
18+
\Fruitcake\Cors\HandleCors::class,
19+
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
20+
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
21+
\App\Http\Middleware\TrimStrings::class,
22+
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
23+
];
24+
25+
/**
26+
* The application's route middleware groups.
27+
*
28+
* @var array
29+
*/
30+
protected $middlewareGroups = [
31+
'web' => [
32+
\App\Http\Middleware\EncryptCookies::class,
33+
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
34+
\Illuminate\Session\Middleware\StartSession::class,
35+
// \Illuminate\Session\Middleware\AuthenticateSession::class,
36+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
37+
\App\Http\Middleware\VerifyCsrfToken::class,
38+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
39+
],
40+
41+
'api' => [
42+
'throttle:api',
43+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
44+
],
45+
];
46+
47+
/**
48+
* The application's route middleware.
49+
*
50+
* These middleware may be assigned to groups or used individually.
51+
*
52+
* @var array
53+
*/
54+
protected $routeMiddleware = [
55+
'auth' => \App\Http\Middleware\Authenticate::class,
56+
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
57+
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
58+
'can' => \Illuminate\Auth\Middleware\Authorize::class,
59+
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
60+
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
61+
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
62+
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
63+
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
64+
];
65+
}

Diff for: app/Http/Middleware/Authenticate.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Illuminate\Auth\Middleware\Authenticate as Middleware;
6+
7+
class Authenticate extends Middleware
8+
{
9+
/**
10+
* Get the path the user should be redirected to when they are not authenticated.
11+
*
12+
* @param \Illuminate\Http\Request $request
13+
* @return string|null
14+
*/
15+
protected function redirectTo($request)
16+
{
17+
if (! $request->expectsJson()) {
18+
return route('login');
19+
}
20+
}
21+
}

Diff for: app/Http/Middleware/EncryptCookies.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
6+
7+
class EncryptCookies extends Middleware
8+
{
9+
/**
10+
* The names of the cookies that should not be encrypted.
11+
*
12+
* @var array
13+
*/
14+
protected $except = [
15+
//
16+
];
17+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
6+
7+
class PreventRequestsDuringMaintenance extends Middleware
8+
{
9+
/**
10+
* The URIs that should be reachable while maintenance mode is enabled.
11+
*
12+
* @var array
13+
*/
14+
protected $except = [
15+
//
16+
];
17+
}

Diff for: app/Http/Middleware/RedirectIfAuthenticated.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use App\Providers\RouteServiceProvider;
6+
use Closure;
7+
use Illuminate\Support\Facades\Auth;
8+
9+
class RedirectIfAuthenticated
10+
{
11+
/**
12+
* Handle an incoming request.
13+
*
14+
* @param \Illuminate\Http\Request $request
15+
* @param \Closure $next
16+
* @param string|null ...$guards
17+
* @return mixed
18+
*/
19+
public function handle($request, Closure $next, ...$guards)
20+
{
21+
$guards = empty($guards) ? [null] : $guards;
22+
23+
foreach ($guards as $guard) {
24+
if (Auth::guard($guard)->check()) {
25+
return redirect(RouteServiceProvider::HOME);
26+
}
27+
}
28+
29+
return $next($request);
30+
}
31+
}

0 commit comments

Comments
 (0)