API Documentation

DataCollections extends Collection
in package
uses InteractsWithDirectories

Automatically generates Laravel Collections from static data files, such as Markdown components and YAML files using Hyde Autodiscovery.

This class acts both as a base collection class, a factory for creating collections, and static facade shorthand helper methods.

The static "facade" methods are what makes this class special, they allow you to quickly access the data collections.

To use them retrieve a collection, call a facade method with the name of the data collection subdirectory directory.

All collections are indexed by their filename, which is relative to the configured data collection source directory.

Table of Contents

Properties

$sourceDirectory  : string
The base directory for all data collections. Can be modified using a service provider.

Methods

json()  : DataCollections<string, stdClass|array<string|int, mixed>>
Get a collection of JSON documents in the resources/collections/<$key> directory.
markdown()  : DataCollections<string, MarkdownDocument>
Get a collection of Markdown documents in the resources/collections/<$key> directory.
yaml()  : DataCollections<string, FrontMatter>
Get a collection of YAML documents in the resources/collections/<$key> directory.
findFiles()  : Collection
makeIdentifier()  : string
needsDirectories()  : void
Ensure the supplied directories exist by creating them if they don't.
needsDirectory()  : void
Ensure the supplied directory exist by creating it if it does not.
needsParentDirectory()  : void
Ensure the supplied file's parent directory exists by creating it if it does not.

Properties

$sourceDirectory

The base directory for all data collections. Can be modified using a service provider.

public static string $sourceDirectory = 'resources/collections'

Methods

json()

Get a collection of JSON documents in the resources/collections/<$key> directory.

public static json(string $name[, bool $asArray = false ]) : DataCollections<string, stdClass|array<string|int, mixed>>

Each JSON file will be parsed into a stdClass object, or an associative array, depending on the second parameter.

Parameters
$name : string
$asArray : bool = false
Return values
DataCollections<string, stdClass|array<string|int, mixed>>

findFiles()

protected static findFiles(string $name, array<string|int, mixed>|string $extensions) : Collection
Parameters
$name : string
$extensions : array<string|int, mixed>|string
Return values
Collection

makeIdentifier()

protected static makeIdentifier(string $path) : string
Parameters
$path : string
Return values
string

needsDirectories()

Ensure the supplied directories exist by creating them if they don't.

protected static needsDirectories(array<string|int, string> $directories) : void
Parameters
$directories : array<string|int, string>

array with relative file paths to the directories

needsDirectory()

Ensure the supplied directory exist by creating it if it does not.

protected static needsDirectory(string $directory) : void
Parameters
$directory : string

relative file path to the directory

needsParentDirectory()

Ensure the supplied file's parent directory exists by creating it if it does not.

protected static needsParentDirectory(string $file[, int $levels = 1 ]) : void
Parameters
$file : string
$levels : int = 1

        
On this page

Search results