generated from archtechx/template
-
Notifications
You must be signed in to change notification settings - Fork 24
/
SEOServiceProvider.php
58 lines (45 loc) · 1.6 KB
/
SEOServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace ArchTech\SEO;
use ArchTech\SEO\Commands\GenerateFaviconsCommand;
use Illuminate\Support\ServiceProvider;
use ImLiam\BladeHelper\BladeHelperServiceProvider;
use ImLiam\BladeHelper\Facades\BladeHelper;
class SEOServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton('seo', SEOManager::class);
$this->app->register(BladeHelperServiceProvider::class);
}
public function boot(): void
{
$this->loadViewsFrom(__DIR__ . '/../assets/views', 'seo');
if ($this->app->runningInConsole()) {
$this->commands([
GenerateFaviconsCommand::class,
]);
}
$this->publishes([
__DIR__ . '/../assets/views' => resource_path('views/vendor/seo'),
], 'seo-views');
BladeHelper::directive('seo', function (...$args) {
// Flipp supports more arguments
if ($args[0] === 'flipp') {
array_shift($args);
return seo()->flipp(...$args);
}
// Two arguments indicate that we're setting a value, e.g. `@seo('title', 'foo')
if (count($args) === 2) {
return seo()->set($args[0], $args[1]);
}
// An array means we don't return anything, e.g. `@seo(['title' => 'foo'])
if (is_array($args[0])) {
seo($args[0]);
return null;
}
// A single value means we fetch a value, e.g. `@seo('title')
return seo()->get($args[0]);
});
}
}