@@ -16,11 +16,12 @@ laravel project
16
16
- create a directory called Admin in "App/Modules" folder ex. app/Modules/Admin
17
17
- open config/modules.php file and add following line:
18
18
19
- `
19
+ ``` php
20
20
return [
21
21
'admin' => 'Admin Module'
22
22
];
23
- `
23
+ ```
24
+
24
25
That is it your module is now enabled for your project. Following will be the ideal
25
26
structure for your admin module
26
27
@@ -34,15 +35,21 @@ App<br>
34
35
To access your module configuration use lowercase module name
35
36
Ex.
36
37
37
- ` $admin_config = config('admin'); `
38
+ ``` php
39
+ $admin_config = config('admin');
40
+ ```
38
41
39
42
To use admin views in your controller use:
40
43
41
- ` return view('admin::index'); `
44
+ ``` php
45
+ return view('admin::index');
46
+ ```
42
47
43
48
or
44
49
45
- ` return view('admin::folder.file'); `
50
+ ``` php
51
+ return view('admin::folder.file');
52
+ ```
46
53
47
54
### Sample Admin Module Code
48
55
@@ -56,40 +63,36 @@ Create a file called "config.php" in App/Modules/Admin
56
63
57
64
First, define a route in App/Modules/Admin/routes.php file as shown below:
58
65
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
60
71
61
- Secondly, create a file called "HomeController.php" in App/Modules/Admin/Controllers with following contents:
62
- `
72
+ ``` php
63
73
<?php
64
74
65
75
namespace App\Modules\Admin\Controllers;
66
-
67
76
use App\Http\Controllers\Controller;
68
77
69
78
class HomeController extends Controller
70
79
{
71
80
public function index()
72
81
{
73
82
dd( config('modules') );
74
-
75
- return view('admin::index');
76
83
}
77
84
}
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
+ ```
84
86
85
87
Now, once we have folder and file structure defined we have to enable admin module:
86
88
87
89
open config/modules.php file and add following line:
88
90
89
91
90
- `return [
92
+ ``` php
93
+ return [
91
94
'admin' => 'Admin Panel'
92
95
];
93
- `
96
+ ```
94
97
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