Skip to content

Commit d10ed81

Browse files
committed
build readme;
1 parent f17e408 commit d10ed81

File tree

3 files changed

+84
-28
lines changed

3 files changed

+84
-28
lines changed

README.md

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
![](./.github/laravel-breadcrumbs.png)
22

3-
# Quick and easy breadcrumbs for Laravel
4-
5-
**Note:** This is very much a work in progress and should not be used on any live site.
6-
73
[![Latest Version on Packagist](https://img.shields.io/packagist/v/aelora/laravel-breadcrumbs.svg?style=flat-square)](https://packagist.org/packages/aelora/laravel-breadcrumbs)
8-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/aelora/laravel-breadcrumbs/run-tests?label=tests)](https://github.com/aelora/laravel-breadcrumbs/actions?query=workflow%3Arun-tests+branch%3Amain)
9-
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/aelora/laravel-breadcrumbs/Check%20&%20fix%20styling?label=code%20style)](https://github.com/aelora/laravel-breadcrumbs/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
104
[![Total Downloads](https://img.shields.io/packagist/dt/aelora/laravel-breadcrumbs.svg?style=flat-square)](https://packagist.org/packages/aelora/laravel-breadcrumbs)
115

12-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
13-
14-
## Support us
15-
16-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-breadcrumbs.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-breadcrumbs)
17-
18-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
19-
20-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
6+
Quickly build breadcrumb trails for your pages in Laravel and automatically output the HTML and JSON-LD schema metadata.
217

228
## Installation
239

@@ -30,35 +16,107 @@ composer require aelora/laravel-breadcrumbs
3016
You can publish the config file with:
3117

3218
```bash
33-
php artisan vendor:publish --tag="laravel-breadcrumbs-config"
19+
php artisan vendor:publish --tag="breadcrumbs-config"
3420
```
3521

3622
This is the contents of the published config file:
3723

3824
```php
3925
return [
26+
'home' => [
27+
28+
// Should the home link be automatically included in the breadcrumbs? You can also manually include
29+
// or exclude the home link when you build the breadcrumb class.
30+
'include' => true,
31+
32+
'text' => 'Home',
33+
34+
'url' => url('/'),
35+
36+
'image' => '',
37+
],
38+
39+
// Which blade template to use. Currently only tailwind is supported.
40+
'theme' => 'tailwind',
41+
42+
// View to use to generate the HTML breadcrumbs. If defined, this will
43+
// override the theme above.
44+
'view' => '',
45+
46+
// Character to use as a separator between crumbs. Use and encoded entity
47+
// if you want something like >
48+
'separator' => '/',
4049
];
4150
```
4251

4352
Optionally, you can publish the views using
4453

4554
```bash
46-
php artisan vendor:publish --tag="laravel-breadcrumbs-views"
55+
php artisan vendor:publish --tag="breadcrumbs-views"
4756
```
4857

58+
Currently the only two views are `jsonld.blade.php` which is used for the Schema metadata and `breadcrumbs-tailwind.blade.css`.
59+
4960
## Usage
5061

5162
```php
52-
$breadcrumbs = new Aelora\Breadcrumbs();
53-
echo $breadcrumbs->echoPhrase('Hello, Aelora!');
63+
// In your controller
64+
use Aelora\Breadcrumbs\Breadcrumbs;
65+
$breadcrumbs = Breadcrumbs::create()
66+
->add('Page #1', url('/page-1'))
67+
->add('Page #2', url('/page-2'))
68+
->add('Current Page');
69+
70+
return view('some.view.file', ['breadcrumbs' => $breadcrumbs]);
5471
```
5572

56-
## Testing
57-
58-
```bash
59-
composer test
73+
```php
74+
// In your view where ever your want the breadcrumbs
75+
{!! $breadcrumbs !!}
6076
```
6177

78+
You can also call `$breadcrumbs->generate()` for the same effect. `Breadcrumbs` implements `Stringable` and has a `__toString()` method, so you don't need to. The `__toString()` calls `generate()`.
79+
80+
Note that we're using `{!!` and `!!}` instead of `{{` and `}}`. We don't want the contents of the breadcrumbs to be escaped.
81+
82+
### Home Page
83+
84+
You don't need to explicitly add your home page to the breadcrumbs. With the default config, it will be added automatically as the first element before output. If you don't want to include the home page link you can set `home.include` to `false` in the config file or call `setHome(false)` when you're creating the breadcrumbs.
85+
86+
## Methods
87+
88+
`public function add(string $title, string $url = '', string $image = '')`
89+
90+
Adds a new breadcrumb link on the end of the current stack.
91+
92+
The only required parameter is `$title`. Breadcrumbs will only be links if `$url` is not empty. If it is, `$title` will display unlinked. `$image` is a link to an image for the breadcrumb. It's currently only used in the schema metadata and not in the visible HTML output, although it could be if you build your own view.
93+
94+
`public function count()`
95+
96+
Returns the number of breadcrumb items, not counting the home link.
97+
98+
`public static function create()`
99+
100+
Returns a new instance so you can build on one line without having to call `new Breadcrumbs()`.
101+
102+
`public function generate($echo = false)`
103+
104+
Returns the generated breadcrumbs, both the visible HTML and schema metadata. If `$echo` is `true` then the breadcrumbs will also be echoed prior to return.
105+
106+
`public function reset()`
107+
108+
Clears the breadcrumb trail.
109+
110+
`public function reverse()`
111+
112+
Reverses the internal breadcrumb trail. Sometimes it's easier to build the trail backwards and then flip it at the end.
113+
114+
`public function setHome($title, string $url = '', string $image = '')`
115+
116+
Allows you to change the home link for individual pages without having to change the config file. Parameters are the same as the `add` method.
117+
118+
If `$title` is `false` then the home link will not be included. Otherwise it should be a `string`.
119+
62120
## Changelog
63121

64122
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
@@ -67,10 +125,6 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re
67125

68126
Please see [CONTRIBUTING](https://github.com/RyanNutt/.github/blob/main/CONTRIBUTING.md) for details.
69127

70-
## Security Vulnerabilities
71-
72-
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
73-
74128
## Credits
75129

76130
- [Ryan Nutt](https://github.com/RyanNutt)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"laravel",
77
"laravel-breadcrumbs"
88
],
9-
"homepage": "https://github.com/aelora/laravel-breadcrumbs",
9+
"homepage": "https://github.com/RyanNutt/laravel-breadcrumbs",
1010
"license": "MIT",
1111
"authors": [
1212
{

src/Breadcrumbs.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public function generate(bool $echo = false): string
115115

116116
$out .= view('breadcrumbs::jsonld', ['jsonld' => $jsonld, 'crumbs' => $this->crumbs])->render();
117117

118+
if ($echo) echo $out;
119+
118120
return $out;
119121
}
120122

0 commit comments

Comments
 (0)