Skip to content

Commit 8833c5c

Browse files
authored
Merge pull request #5 from webfactor/2.1
2.1
2 parents 672a662 + d1f0590 commit 8833c5c

File tree

3 files changed

+76
-8
lines changed

3 files changed

+76
-8
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/RouteService.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99

1010
class RouteService extends ServiceAbstract implements ServiceInterface
1111
{
12-
protected $relativeToBasePath = 'routes';
12+
protected $relativeToBasePath = 'routes/backpack';
1313

14-
private $adminFile;
14+
protected $fileName = 'custom.php';
15+
16+
private $routeFile;
1517

1618
public function call()
1719
{
18-
$this->adminFile = $this->getFilePath();
20+
$this->routeFile = $this->getFilePath();
1921

20-
if ($this->filesystem->exists($this->adminFile)) {
22+
if ($this->filesystem->exists($this->routeFile)) {
2123
$this->writeFile();
24+
$this->addLatestFileToIdeStack();
2225
}
23-
24-
$this->addLatestFileToIdeStack();
2526
}
2627

2728
private function getRouteName(): string
@@ -43,12 +44,12 @@ private function getControllerName(): string
4344
*/
4445
private function writeFile()
4546
{
46-
$this->filesystem->append($this->adminFile, $this->getRouteString());
47+
$this->filesystem->append($this->routeFile, $this->getRouteString());
4748
}
4849

4950
private function getFilePath()
5051
{
51-
return base_path('routes') . '/admin.php';
52+
return base_path($this->relativeToBasePath) . '/' . $this->fileName;
5253
}
5354

5455
private function getRouteString()

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)