├── CHANGELOG.md ├── .gitignore ├── img.png ├── config └── code-insights.php ├── src ├── Routes │ └── web.php ├── Helpers │ └── Helper.php ├── CodeGeneratorServiceProvider.php ├── Http │ └── Controllers │ │ └── CodeDocController.php └── Services │ └── CodeDocService.php ├── LICENSE.md ├── composer.json ├── resources ├── assets │ └── css │ │ ├── dark-theme.css │ │ └── style.css └── views │ └── doc.blade.php ├── CONTRIBUTING.md └── README.md /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | composer.lock 3 | .idea/ 4 | -------------------------------------------------------------------------------- /img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcian/laravel-code-insights/HEAD/img.png -------------------------------------------------------------------------------- /config/code-insights.php: -------------------------------------------------------------------------------- 1 | env('CODE_INSIGHTS_PATH', 'code-insights'), 15 | 16 | 'public' => [ 17 | 'folder' => 'laravel-code-insights' 18 | ] 19 | ]; 20 | -------------------------------------------------------------------------------- /src/Routes/web.php: -------------------------------------------------------------------------------- 1 | name('code_docs'); 17 | -------------------------------------------------------------------------------- /src/Helpers/Helper.php: -------------------------------------------------------------------------------- 1 | getMethod($methodName); 16 | 17 | $startLine = $reflectionMethod->getStartLine(); 18 | $endLine = $reflectionMethod->getEndLine(); 19 | $filename = $reflectionMethod->getFileName(); 20 | 21 | if ($filename !== false) { 22 | $lines = file($filename); 23 | $methodCode = implode("", array_slice($lines, $startLine - 1, $endLine - $startLine + 1)); 24 | return '
' . $methodCode . ''; 25 | 26 | } else { 27 | return "Unable to retrieve the source code of the method."; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CodeGeneratorServiceProvider.php: -------------------------------------------------------------------------------- 1 | loadRoutesFrom(__DIR__ . '/Routes/web.php'); 23 | $this->loadRoutesFrom(__DIR__ . '/Helpers/Helper.php'); 24 | $this->loadViewsFrom(__DIR__ . '/../resources/views', 'laravel-code-insights'); 25 | 26 | //Publish 27 | $this->publishes([__DIR__ . '/../resources/assets' => public_path(config('code-insights.public.folder').'/assets')], 'public'); 28 | $this->publishes([ 29 | __DIR__.'/../config/code-insights.php' => config_path('code-insights.php'), 30 | ], 'code-insights-config'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 ViitorCloud Technologies 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vcian/laravel-code-insights", 3 | "description": "Display all list of controllers, repositories, models, traits, and helpers, allowing you to easily explore and access them", 4 | "keywords": [ 5 | "document", 6 | "generator", 7 | "code", 8 | "controllers", 9 | "models", 10 | "methods", 11 | "laravel", 12 | "access", 13 | "optimize" 14 | ], 15 | "license": "MIT", 16 | "authors": [ 17 | { 18 | "name": "Vcian - Viitorcloud", 19 | "email": "administrator@viitorcloud.com", 20 | "role": "Creator" 21 | } 22 | ], 23 | "require": { 24 | "php": "^8.0" 25 | }, 26 | "type": "library", 27 | "autoload": { 28 | "psr-4": { 29 | "Vcian\\LaravelCodeInsights\\": "src/" 30 | }, 31 | "files": [ 32 | "src/CodeGeneratorServiceProvider.php" 33 | ] 34 | }, 35 | "extra": { 36 | "laravel": { 37 | "providers": [ 38 | "Vcian\\LaravelCodeInsights\\CodeGeneratorServiceProvider" 39 | ] 40 | } 41 | }, 42 | "minimum-stability": "dev" 43 | } 44 | -------------------------------------------------------------------------------- /src/Http/Controllers/CodeDocController.php: -------------------------------------------------------------------------------- 1 | class); 27 | $lastTwoSegments = array_slice($segments, -2); 28 | 29 | return view(config('code-insights.public.folder') . '::doc', [ 30 | 'controllers' => $this->codeDocService->getControllers(), 31 | 'models' => $this->codeDocService->getModels(), 32 | 'methods' => $this->codeDocService->getMethods($request->class), 33 | 'repositories' => $this->codeDocService->getRepositories(), 34 | 'services' => $this->codeDocService->getServices(), 35 | 'sourceCode' => $this->codeDocService->sourceCode($request->class), 36 | 'providers' => $this->codeDocService->getProviders(), 37 | 'helpers' => $this->codeDocService->getHelpers(), 38 | 'activeClass' => $request->class, 39 | 'breadcrumb' => (isset($lastTwoSegments[1]) && isset($lastTwoSegments[0])) ? $lastTwoSegments[0] . '/' . $lastTwoSegments[1] : '', //base 40 | ]); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /resources/assets/css/dark-theme.css: -------------------------------------------------------------------------------- 1 | /* Dark theme */ 2 | .dark .hs-accordion.active>.hs-accordion-toggle.dark\:hs-active\:text-white { 3 | --tw-text-opacity: 1; 4 | color: rgb(255 255 255 / var(--tw-text-opacity)); 5 | } 6 | 7 | .dark .tab-main nav button.active { 8 | border-bottom-color: rgb(255 255 255); 9 | color: rgb(255 255 255); 10 | } 11 | 12 | .dark .hs-dark-mode-active\:block { 13 | display: flex; 14 | } 15 | 16 | .dark .hs-dark-mode-active\:hidden { 17 | display: none; 18 | } 19 | 20 | 21 | .dark .dark\:text-white { 22 | --tw-text-opacity: 1; 23 | color: rgb(255 255 255 / var(--tw-text-opacity)); 24 | } 25 | 26 | .dark .dark\:text-red-400 { 27 | --tw-text-opacity: 1; 28 | color: rgb(248 113 113 / var(--tw-text-opacity)); 29 | } 30 | 31 | .dark .dark\:text-slate-300 { 32 | --tw-text-opacity: 1; 33 | color: rgb(203 213 225 / var(--tw-text-opacity)); 34 | } 35 | 36 | .dark .dark\:text-slate-400 { 37 | --tw-text-opacity: 1; 38 | color: rgb(148 163 184 / var(--tw-text-opacity)); 39 | } 40 | 41 | .dark .dark\:bg-slate-600 { 42 | --tw-bg-opacity: 1; 43 | background-color: rgb(71 85 105 / var(--tw-bg-opacity)); 44 | } 45 | 46 | .dark .dark\:bg-slate-700 { 47 | --tw-bg-opacity: 1; 48 | background-color: rgb(51 65 85 / var(--tw-bg-opacity)); 49 | } 50 | 51 | .dark .dark\:bg-slate-800 { 52 | --tw-bg-opacity: 1; 53 | background-color: rgb(30 41 59 / var(--tw-bg-opacity)); 54 | } 55 | 56 | .dark .dark\:hover\:bg-slate-600:hover { 57 | --tw-bg-opacity: 1; 58 | background-color: rgb(71 85 105 / var(--tw-bg-opacity)); 59 | } 60 | 61 | 62 | .dark .dark\:border-slate-600 { 63 | --tw-border-opacity: 1; 64 | border-color: rgb(71 85 105 / var(--tw-border-opacity)); 65 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/vcian/laravel-db-auditor). 6 | 7 | Please read and understand the contribution guide before creating an issue or pull request. 8 | 9 | ## Protocol 10 | 11 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 12 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 13 | extremely unfair for them to suffer abuse or anger for their hard work. 14 | 15 | ## Pull Requests 16 | 17 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 18 | 19 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 20 | 21 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 22 | 23 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 24 | 25 | - **Create feature branches** - Don't ask us to pull from your master branch. 26 | 27 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 28 | 29 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 30 | 31 | **Happy coding**! 32 | -------------------------------------------------------------------------------- /resources/assets/css/style.css: -------------------------------------------------------------------------------- 1 | /* Sidebar css */ 2 | 3 | .hs-accordion.active>.hs-accordion-toggle.hs-active\:text-blue-500 { 4 | --tw-text-opacity: 1; 5 | color: rgb(59 130 246 / var(--tw-text-opacity)); 6 | } 7 | 8 | /* .hs-accordion.active > .hs-accordion-toggle.hs-accordion-active\:text-blue-600 */ 9 | /* .hs-accordion.active>.hs-accordion-toggle.hs-accordion-active\:hover\:bg-transparent:hover { 10 | background-color: transparent; 11 | } */ 12 | 13 | .hs-accordion.active>.hs-accordion-toggle .arrow-icon { 14 | rotate: -180deg; 15 | } 16 | 17 | /* Tab css */ 18 | .tab-main nav button.active { 19 | border-bottom-color: rgb(59 130 246); 20 | color: rgb(59 130 246); 21 | } 22 | 23 | /* text-slate-700 removed and used below class in submenu (in anchor tag)*/ 24 | .active-submenu { 25 | color: rgb(59 130 246 / var(--tw-text-opacity)); 26 | } 27 | 28 | .accordion-header { 29 | cursor: pointer; 30 | display: block; 31 | line-height: 40px; 32 | font-size: 20px; 33 | position: relative; 34 | background-color: #ffffff; 35 | color: #373737; 36 | padding: 0 55px 0 20px; 37 | } 38 | 39 | .accordion-header>span { 40 | position: absolute; 41 | border-radius: 50%; 42 | padding: 12px; 43 | right: 20px; 44 | top: 50%; 45 | height: 25px; 46 | width: 25px; 47 | transform: translateY(-50%); 48 | cursor: pointer; 49 | } 50 | 51 | .accordion-header>span::before { 52 | position: absolute; 53 | content: ""; 54 | left: 50%; 55 | top: 50%; 56 | height: 14px; 57 | width: 2px; 58 | background-color: rgb(51 65 85 / var(--tw-text-opacity)); 59 | transform: translate(-50%, -50%); 60 | transition: transform cubic-bezier(0.165, 0.84, 0.44, 1) 0.3s; 61 | } 62 | .dark .accordion-header>span::before, .dark .accordion-header>span::after { 63 | background-color:#ffffff; 64 | } 65 | 66 | .accordion-header>span::after { 67 | position: absolute; 68 | content: ""; 69 | left: 50%; 70 | top: 50%; 71 | height: 14px; 72 | width: 2px; 73 | background-color: rgb(51 65 85 / var(--tw-text-opacity)); 74 | transform: translate(-50%, -50%) rotate(90deg); 75 | } 76 | 77 | .accordion-open .accordion-header>span::before { 78 | transform: translate(-50%, -50%) rotate(90deg); 79 | } 80 | 81 | .accordion-body { 82 | display: none; 83 | } 84 | 85 | .acc-btn>a { 86 | text-decoration: none; 87 | display: inline-block; 88 | height: 40px; 89 | line-height: 40px; 90 | background-color: #ffffff; 91 | color: #373737; 92 | box-shadow: 5px 5px 0px 0 #000000; 93 | padding: 0 20px; 94 | margin: 0 10px 10px 10px; 95 | font-size: 18px; 96 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |
_About_
6 |This package serves as a code insight for Laravel applications.
10 | -It presents a comprehensive list of controllers, repositories, models, traits, and helpers, allowing you to easily explore and access them. When selecting a controller, it displays its functions and corresponding source code. It also includes an optimization feature.
11 | 12 | ##_Installation & Usage_
13 |Requires [PHP 8.0+] | [Laravel 8.0+]
15 |Require Laravel Code Insights using : [Composer]
16 | 17 | ```bash 18 | composer require --dev vcian/laravel-code-insights 19 | ``` 20 | ##_Usage_
21 | 22 | php artisan vendor:publish --tag=public 23 |You can access Code Insights view via below route
27 |Access Route: http://yourdomain.com/code-insights
28 |Note:
31 |1) Don't forget to replace your actual domain with "yourdomain.com"
32 |2) You can also update your custom route with config/code-insights.php
33 | 34 |  35 | 36 |


_Changelog_
41 | 42 | 43 | >Please see [CHANGELOG] for more information what has changed recently.
44 | 45 | ##_Contributing_
46 | 47 | 48 |Please see [CONTRIBUTING] for details.
49 |50 | 51 | We believe in 52 | 👇 53 | ACT NOW 54 | PERFECT IT LATER 55 | CORRECT IT ON THE WAY. 56 |
57 | 58 | ##_Security_
59 | 60 |If you discover any security-related issues, please email ruchit.patel@viitor.cloud instead of using the issue tracker.
61 | 62 | ##_Credits_
63 | 64 | - [All Contributors](../../contributors) 65 | 66 | ##_License_
67 | 68 |The MIT License (MIT). Please see [License File] for more information.
69 | -------------------------------------------------------------------------------- /src/Services/CodeDocService.php: -------------------------------------------------------------------------------- 1 | getRelativePathname() 35 | ); 36 | 37 | if (class_exists($class)) { 38 | $reflectionClass = new ReflectionClass($class); 39 | $controllers->push([ 40 | 'name' => $class, 41 | 'shortName' => $reflectionClass->getShortName() 42 | ]); 43 | } 44 | } 45 | } catch (Exception $ex) { 46 | Log::error($ex); 47 | } 48 | 49 | return $controllers; 50 | } 51 | 52 | /** 53 | * @return Collection 54 | */ 55 | public function getModels(): Collection 56 | { 57 | $models = collect(); 58 | 59 | try { 60 | $modelPath = app_path('Models'); 61 | $files = File::allFiles($modelPath); 62 | 63 | foreach ($files as $file) { 64 | $namespace = 'App\\Models\\'; 65 | $class = $namespace . str_replace( 66 | ['/', '.php'], 67 | ['\\', ''], 68 | $file->getRelativePathname() 69 | ); 70 | 71 | if (class_exists($class)) { 72 | $reflectionClass = new ReflectionClass($class); 73 | // Check if the class is a controller 74 | if (!$reflectionClass->isAbstract()) { 75 | $models->push([ 76 | 'name' => $class, 77 | 'shortName' => $reflectionClass->getShortName() 78 | ]); 79 | } 80 | } 81 | } 82 | } catch (Exception $ex) { 83 | Log::error($ex); 84 | } 85 | 86 | return $models; 87 | } 88 | 89 | /** 90 | * @param string|null $class 91 | * @return Collection 92 | */ 93 | public function getMethods(?string $class): Collection 94 | { 95 | $methods = collect(); 96 | if (class_exists($class) || trait_exists($class)) { 97 | $reflectionClass = new ReflectionClass($class); 98 | foreach ($reflectionClass->getMethods() as $method) { 99 | // Check if the method belongs to the class itself, and not to a parent class 100 | if ($method->class === $class && !$method->isStatic() && $method->getName() !== '__construct' && !str_contains($method->getFileName(), 'vendor')) { 101 | $methods->push([ 102 | 'name' => $method->getName() 103 | ]); 104 | } 105 | } 106 | } 107 | 108 | return $methods; 109 | } 110 | 111 | /** 112 | * @return Collection 113 | */ 114 | public function getRepositories(): Collection 115 | { 116 | $repositories = collect(); 117 | 118 | try { 119 | $repositoryPath = app_path('Repositories'); 120 | $files = File::allFiles($repositoryPath); 121 | 122 | foreach ($files as $file) { 123 | $filePath = $file->getRealPath(); 124 | $namespace = 'App\\Repositories\\'; 125 | $class = $namespace . str_replace( 126 | ['/', '.php'], 127 | ['\\', ''], 128 | $file->getRelativePathname() 129 | ); 130 | 131 | if (class_exists($class)) { 132 | $reflectionClass = new ReflectionClass($class); 133 | 134 | // Check if the class is a controller 135 | if (!$reflectionClass->isAbstract()) { 136 | $repositories->push([ 137 | 'name' => $class, 138 | 'shortName' => $reflectionClass->getShortName() 139 | ]); 140 | } 141 | } 142 | } 143 | } catch (Exception $ex) { 144 | 145 | } 146 | 147 | return $repositories; 148 | } 149 | 150 | /** 151 | * Get Services function 152 | * 153 | * @return Collection 154 | */ 155 | public function getServices(): Collection 156 | { 157 | $services = collect(); 158 | 159 | try { 160 | $servicePath = app_path('Services'); 161 | $files = File::allFiles($servicePath); 162 | 163 | foreach ($files as $file) { 164 | $namespace = 'App\\Services\\'; 165 | $class = $namespace . str_replace( 166 | ['/', '.php'], 167 | ['\\', ''], 168 | $file->getRelativePathname() 169 | ); 170 | 171 | if (class_exists($class)) { 172 | $reflectionClass = new ReflectionClass($class); 173 | 174 | // Check if the class is a controller 175 | if (!$reflectionClass->isAbstract()) { 176 | $services->push([ 177 | 'name' => $class, 178 | 'shortName' => $reflectionClass->getShortName() 179 | ]); 180 | } 181 | } 182 | } 183 | } catch (Exception $ex) { 184 | Log::error($ex); 185 | } 186 | 187 | return $services; 188 | } 189 | 190 | /** 191 | * @param $className 192 | * @return mixed 193 | * @throws ReflectionException 194 | */ 195 | public function sourceCode($className) 196 | { 197 | if ($className) { 198 | $reflectionClass = new ReflectionClass($className); 199 | return file_get_contents($reflectionClass->getFileName()); 200 | } 201 | 202 | return null; 203 | } 204 | 205 | /** 206 | * get providers function 207 | * 208 | * @return Collection 209 | */ 210 | public function getProviders(): Collection 211 | { 212 | $providers = collect(); 213 | 214 | try { 215 | $providerPath = app_path('Providers'); 216 | $files = File::glob($providerPath . '/*.php'); 217 | 218 | foreach ($files as $file) { 219 | $className = basename($file, '.php'); 220 | $providers->push([ 221 | 'name' => "App\\Providers\\" . $className, 222 | 'shortName' => $className, 223 | ]); 224 | } 225 | } catch (Exception $ex) { 226 | Log::error($ex); 227 | } 228 | 229 | return $providers; 230 | } 231 | 232 | /** 233 | * Get helpers function 234 | * 235 | * @return Collection 236 | */ 237 | public function getHelpers(): Collection 238 | { 239 | $helpers = collect(); 240 | 241 | try { 242 | $helperPath = app_path('Helpers'); 243 | $files = File::allFiles($helperPath); 244 | 245 | foreach ($files as $file) { 246 | $namespace = 'App\\Helpers\\'; 247 | $class = $namespace . str_replace( 248 | ['/', '.php'], 249 | ['\\', ''], 250 | $file->getRelativePathname() 251 | ); 252 | 253 | if (class_exists($class)) { 254 | $reflectionClass = new ReflectionClass($class); 255 | // Check if the class is a controller 256 | if (!$reflectionClass->isAbstract()) { 257 | $helpers->push([ 258 | 'name' => $class, 259 | 'shortName' => $reflectionClass->getShortName() 260 | ]); 261 | } 262 | } 263 | } 264 | 265 | } catch (Exception $ex) { 266 | Log::error($ex); 267 | } 268 | 269 | return $helpers; 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /resources/views/doc.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |{{$activeClass}}
346 |{{$sourceCode}}
368 | This package serves as a code insight for Laravel applications.
375 |It presents a comprehensive list of controllers, repositories, models, traits, and helpers, allowing you to easily explore and access them. When selecting a controller, it displays its functions and corresponding source code. It also includes an optimization feature.
376 |@2023 ViitorCloud Technologies. All rights reserved
382 |