Skip to content

Commit d1f0590

Browse files
committed
[EH] add SidebarService
1 parent 3e47e70 commit d1f0590

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

config/generators.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Webfactor\Laravel\Generators\Services\FactoryService::class,
1515
Webfactor\Laravel\Generators\Services\SeederService::class,
1616
Webfactor\Laravel\Generators\Services\RouteService::class,
17+
Webfactor\Laravel\Generators\Services\SidebarService::class,
1718
Webfactor\Laravel\Generators\Services\OpenIdeService::class,
1819
],
1920

src/Services/SidebarService.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Webfactor\Laravel\Generators\Services;
4+
5+
use Illuminate\Filesystem\Filesystem;
6+
use Webfactor\Laravel\Generators\Commands\MakeEntity;
7+
use Webfactor\Laravel\Generators\Contracts\ServiceAbstract;
8+
use Webfactor\Laravel\Generators\Contracts\ServiceInterface;
9+
10+
class SidebarService extends ServiceAbstract implements ServiceInterface
11+
{
12+
protected $relativeToBasePath = 'resources/views/vendor/backpack/base/inc';
13+
14+
protected $fileName = 'sidebar_content.blade.php';
15+
16+
private $sidebarFile;
17+
18+
public function call()
19+
{
20+
$this->sidebarFile = $this->getFilePath();
21+
22+
if ($this->filesystem->exists($this->sidebarFile)) {
23+
$this->writeFile();
24+
$this->addLatestFileToIdeStack();
25+
}
26+
}
27+
28+
private function getRouteName(): string
29+
{
30+
return strtolower($this->command->entity);
31+
}
32+
33+
private function getLanguageName(): string
34+
{
35+
return snake_case($this->command->entity);
36+
}
37+
38+
/**
39+
* Build the class with the given name.
40+
*
41+
* @param string $name
42+
*
43+
* @return string
44+
*/
45+
private function writeFile()
46+
{
47+
$this->filesystem->append($this->sidebarFile, $this->getRouteString());
48+
}
49+
50+
private function getFilePath()
51+
{
52+
return base_path($this->relativeToBasePath) . '/' . $this->fileName;
53+
}
54+
55+
private function getRouteString()
56+
{
57+
return <<<FILE
58+
59+
<li>
60+
<a href="{{ backpack_url('{$this->getRouteName()}') }}">
61+
<i class="fa fa-question"></i><span>{{ trans('models.{$this->getLanguageName()}.plural') }}</span>
62+
</a>
63+
</li>
64+
FILE;
65+
}
66+
}

0 commit comments

Comments
 (0)