diff --git a/docs/Examples.md b/docs/Examples.md deleted file mode 100644 index e69de29..0000000 diff --git a/docs/Queries.md b/docs/Queries.md index e69de29..07d5db8 100644 --- a/docs/Queries.md +++ b/docs/Queries.md @@ -0,0 +1,92 @@ +--- +gitea: none +include_toc: true +--- + +# Queries + +## Graph or Tree + +Queries can return results in 2 formats. A graph or a tree. + +Graphs results are a collection of records (nodes) and a collection of edges. This format is more useful for network visualization. + +The tree format is more straightforward as it returns a collection of records. Each record has a **_children** and a **_parents** field and the tree can continue upwards or downwards according to the depth you have requested. + +For example to request records with their children and their children's children: + +```php +$query->childrenDepth(2); +``` +Maybe you only want to get a specific type of relationship: + +```php +$query->childrenDepth(2)->childrenFields(["categories"]); +``` + +## Filters + +You can filter your query with the following format: + +```php +$query->filter(["field_operator" => "value"]); + +// example: + +$query->filter(["date_lt" => "2020-09-15"]); +``` + +Or filters are also available: + +```php +$query + ->filter(["price_eqn" => 10]) + ->orFilter(["title_regex" => "search", "slug_regex" => "search"]) + ; +``` +## Operator List + +- regex +- eq +- ne +- eqnum +- neqnum +- filter +- eqtrue +- eqfalse +- netrue +- nefalse +- in: +- innum +- nin +- ninnum +- lt +- lte +- gt +- gte +- null +- nnull +- exists +- nexists + +## Example + +Get 10 posts from the sports category as a tree + + +```php +$posts = $query + ->filter([ + "schema" => "posts", + "children.categories.data.slug" => "sports", + ] + ) + ->childrenDepth(1) + ->limit(10) + ->tree(); + +$posts->map(...)->toArray(); + +``` + + diff --git a/docs/Website Setup.md b/docs/Website Setup.md new file mode 100644 index 0000000..f32192b --- /dev/null +++ b/docs/Website Setup.md @@ -0,0 +1,101 @@ +# Website Setup + +This is an opinionated website setup. It's irrelevant to both Lucent and Laravel. It is just the way I like to organize everything. + +## Summary + +- Create a Lucent folder with Schemas, Image Filters and Pages +- Pages are similar to controllers, but will also get used to statically generate the website +- A Context singleton class that acts as a container for global state +- A middleware to initiate the Context class and set the application state for the request +- Some helper functions to make our life easier + + +## Context Class + +```php + Homepage::class, + ]; + + public function __construct( + public Application $app, + public Query $query + ){} + + public function render(string $pageName, ...$args): string + { + $page = $this->app->make($this->pages[$pageName]); + return $page->render(...$args); + } + + public function getTitle() + { + return empty($this->title) ? $this->website : $this->title . " | " . $this->website; + } + + public function getFullUrl(string $path = "") + { + return config("app.url") . $this->generateLocaleUrl($path, $this->locale); + } + + public function localeUrl(string $path = ""): string + { + return $this->generateLocaleUrl($path, $this->locale); + } + + public function switchLocale(string $locale, $path = ""): string + { + return $this->generateLocaleUrl($path, $locale); + } + + private function generateLocaleUrl(string $path, string $locale): string + { + if ($this->mode == "preview") { + return config("app.url") . "/preview/" . $locale . "/" . trim($path, "/"); + } + return config("app.url") . "/" . $locale . "/" . trim($path, "/"); + } +} +``` + +Add this class to `AppServiceProvider` as a singleton + +```php + $this->app->singleton(Context::class); +``` + +## Context Middleware + +```php +context->locale = $request->route("locale"); + App::setLocale($this->meta->locale); + $this->context->mode = $mode; + $this->context->loadData(); + return $next($request); + } +} +``` + +Add the middleware inside the HTTP Kernel file. \ No newline at end of file diff --git a/src/Config/main.php b/src/Config/main.php index 69c290b..5e91321 100644 --- a/src/Config/main.php +++ b/src/Config/main.php @@ -1,7 +1,7 @@ env("LUCENT_ENV", env('APP_ENV')), + "env" => env("LUCENT_ENV", "production"), "schemas_path" => env("LUCENT_SCHEMAS_PATH", "app/Lucent"), "database" => env('LUCENT_DB_CONNECTION', env('DB_CONNECTION',"sqlite")), "name" => env("LUCENT_NAME", "Lucent"),