@@ -16,11 +16,12 @@ laravel project
1616- create a directory called Admin in "App/Modules" folder ex. app/Modules/Admin
1717- open config/modules.php file and add following line:
1818
19- `
19+ ``` php
2020return [
2121 'admin' => 'Admin Module'
2222];
23- `
23+ ```
24+
2425That is it your module is now enabled for your project. Following will be the ideal
2526structure for your admin module
2627
@@ -34,15 +35,21 @@ App<br>
3435To access your module configuration use lowercase module name
3536Ex.
3637
37- ` $admin_config = config('admin'); `
38+ ``` php
39+ $admin_config = config('admin');
40+ ```
3841
3942To use admin views in your controller use:
4043
41- ` return view('admin::index'); `
44+ ``` php
45+ return view('admin::index');
46+ ```
4247
4348or
4449
45- ` return view('admin::folder.file'); `
50+ ``` php
51+ return view('admin::folder.file');
52+ ```
4653
4754### Sample Admin Module Code
4855
@@ -56,40 +63,36 @@ Create a file called "config.php" in App/Modules/Admin
5663
5764First, define a route in App/Modules/Admin/routes.php file as shown below:
5865
59- ` Route::get('/', 'HomeController@index')->name('home'); `
66+ ``` php
67+ Route::get('/', 'HomeController@index')->name('home');
68+ ```
69+
70+ Secondly, create a file called "HomeController.php" in App/Modules/Admin/Controllers with following contents
6071
61- Secondly, create a file called "HomeController.php" in App/Modules/Admin/Controllers with following contents:
62- `
72+ ``` php
6373<?php
6474
6575namespace App\Modules\Admin\Controllers;
66-
6776use App\Http\Controllers\Controller;
6877
6978class HomeController extends Controller
7079{
7180 public function index()
7281 {
7382 dd( config('modules') );
74-
75- return view('admin::index');
7683 }
7784}
78- `
79-
80- Finally, create a view file called "index.blade.php" in App/Modules/Admin/Views folder with
81- following content
82-
83- `<h1> Welcome to Admin Module</h1 >`
85+ ```
8486
8587Now, once we have folder and file structure defined we have to enable admin module:
8688
8789open config/modules.php file and add following line:
8890
8991
90- `return [
92+ ``` php
93+ return [
9194 'admin' => 'Admin Panel'
9295];
93- `
96+ ```
9497
95- Done, go to browser and hit your local website instance and see if you get "Welcome to Admin Module" message on your screen
98+ Done, go to browser and hit your local website instance
0 commit comments