Skip to content

Commit 2d431ac

Browse files
author
RK M
committed
updated
1 parent c779b93 commit 2d431ac

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Commands/CoolhaxCrudGenerator.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function handle()
5757
->buildViews();
5858

5959
$this->info('Created Successfully.');
60-
60+
$this->generateRoutes();
6161
return true;
6262
}
6363

@@ -160,6 +160,25 @@ protected function buildViews()
160160
return $this;
161161
}
162162

163+
protected function generateRoutes()
164+
{
165+
$route =$this->options['route'] ?? Str::kebab(Str::plural($this->name));
166+
$routePath = base_path('routes/web.php');
167+
$routeContent = File::get($routePath);
168+
169+
// Define the route string to check and add
170+
$routeString = "Route::resource('" . strtolower($route) . "', '" . $this->name . "Controller');";
171+
172+
// Check if the route string already exists in web.php
173+
if (strpos($routeContent, $routeString) === false) {
174+
// If not, append the route string to the file
175+
File::append($routePath, "\n" . $routeString);
176+
$this->info('Route added successfully.');
177+
} else {
178+
$this->info('Route already exists.');
179+
}
180+
}
181+
163182
/**
164183
* Make the class name from table name.
165184
*

0 commit comments

Comments
 (0)