Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Apr 5, 2024
1 parent 81b1f79 commit 024f5fd
Showing 1 changed file with 77 additions and 5 deletions.
82 changes: 77 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,87 @@ By parsing Frontmatter into **Eloquent models**, Fusion empowers developers to b

You can install the package via composer:

```bash
```shell
composer require hi-folks/fusion
```

## Usage

Once you installed Fusion you can start the process of creating content in Markdown files and querying the files through the Models.
For example, now we are going to create articles in Markdown format and we will parse and query them like you can do it with a database.

### Creating the content
In the `resources/content` directory, you can create the `article` directory.
In the `resources/content/article`, you can create your Markdown files with a frontmatter header like for example:

```markdown
---
date: 2024-04-05
title: Example title for article 1
excerpt: This will be a short excerpt from article number 1.
published: true
---

# Article 1

Markdown goes here
```

you can name this file as `resources/content/article/article-1.md`
You can create similarly the other Markdown files. These files represent your articles.

### Creating the Model
Similarly, you are doing with a database, you can create your model for loading the markdown files.
Because you are creating articles you can create your model as `app/Models/Article.php`.

You can fill the file in this way:

```php
// Usage description here
<?php

namespace App\Models;


use HiFolks\Fusion\Models\FusionBaseModel;
use Sushi\Sushi;

class Article extends FusionBaseModel
{
use Sushi;

public function getRows()
{
return parent::getRows();

}

public function frontmatterFields(): array
{
return [
"excerpt"
];
}

}

```
Consider that:
- the class has to extend the FusionBaseModel with `extends FusionBaseModel`;
- you have to use the trait Sushi: `use Sushi;`
- you have to implement the `getRows()` function returning `return parent::getRows();`
- you have to implement the `frontmatterFields()` function for returning the list of the field names used in the frontmatter header.

### Querying the content
Now in your Controllers or your Blade components, you can use the `Article` model with the usual method like `where()`, `orderBy()` etc:

```php
$articles = \App\Models\Article
::where('published', true)
->orderBy('date')
->get();
```



### Testing

Expand All @@ -29,19 +101,19 @@ composer test

### Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

## Credits

- [Roberto B](https://github.com/hi-folks)
- [Roberto B](https://github.com/roberto-butti)
- [All Contributors](../../contributors)

## License
Expand Down

0 comments on commit 024f5fd

Please sign in to comment.