@@ -24,11 +24,11 @@ return [
24
24
That is it your module is now enabled for your project. Following will be the ideal
25
25
structure for your admin module
26
26
27
- App
28
- |-- Admin
29
- |-- Controllers
30
- |-- Views
31
- |-- config.php
27
+ App< br >
28
+ |-- Admin< br >
29
+ |-- Controllers< br >
30
+ |-- Views< br >
31
+ |-- config.php< br >
32
32
|-- routes.php
33
33
34
34
To access your module configuration use lowercase module name
@@ -42,4 +42,50 @@ To use admin views in your controller use:
42
42
43
43
or
44
44
45
- ` return view('admin::folder.file'); `
45
+ ` return view('admin::folder.file'); `
46
+
47
+ ### Sample Admin Module Code
48
+
49
+ Create a folder called "Admin" in App/Modules
50
+ Create directory called "Controllers" in App/Modules/Admin
51
+ Create directory called "Views" in App/Modules/Admin
52
+ Create a file called "routes.php" in App/Modules/Admin
53
+ Create a file called "config.php" in App/Modules/Admin
54
+
55
+ ### Create Sample Route, Controller and View file
56
+
57
+ First, define a route in App/Modules/Admin/routes.php file as shown below:
58
+
59
+ ` Route::get('/', 'HomeController@index')->name('home'); `
60
+
61
+ Secondly, create a file called "HomeController.php" in App/Modules/Admin/Controllers with following contents:
62
+ `
63
+ <? php
64
+
65
+ namespace App\Modules\Admin\Controllers;
66
+
67
+ use App\Http\Controllers\Controller;
68
+
69
+ class HomeController extends Controller
70
+ {
71
+ public function index()
72
+ {
73
+ dd( config('modules') );
74
+
75
+ return view('admin::index');
76
+ }
77
+ }
78
+ `
79
+ Finally, create a view file called "index.blade.php" in App/Modules/Admin/Views folder with following contents:
80
+
81
+ `<h1> Welcome to Admin Module</h1 >`
82
+
83
+ Now, once we have folder and file structure defined we have to enable admin module:
84
+
85
+ open config/modules.php file and add following line:
86
+
87
+ `return [
88
+ 'admin' => 'Admin Panel'
89
+ ];`
90
+
91
+ Done, go to browser and hit your local website instance and see if you get "Welcome to Admin Module" message on your screen
0 commit comments