Skip to content

Commit 57cdd82

Browse files
committed
update README
1 parent 38d35d1 commit 57cdd82

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,125 @@ This command will copy the package's configuration file to your Laravel applicat
3737
php artisan vendor:publish --tag=LaravelSetupLayout --force
3838
```
3939

40+
## Step 3: how to use 🤔
41+
42+
#### Basic Controller Creation:
43+
44+
To create a controller in Laravel using the` php artisan make:controller` command, you can follow these steps:
45+
```bash
46+
php artisan make:controller HomeController
47+
```
48+
49+
#### Basic View Creation:
50+
To create views in Laravel using the php artisan make:view command, you can follow these steps:
51+
52+
```bash
53+
php artisan make:view home
54+
```
55+
This command will create a view file named `home.blade.php` in the resources/views directory by default.
56+
57+
58+
#### Creating a Controller in a Subdirectory:
59+
If you want to create a controller in a subdirectory like /Dashboard, you can specify the directory structure as part of the controller name:
60+
61+
```bash
62+
php artisan make:controller Dashboard/HomeController
63+
```
64+
This command will create a HomeController within the app/Http/Controllers/Dashboard directory.
65+
66+
#### Basic View Creation:
67+
If you want to create a view in a subdirectory like dashboard, you can specify the directory structure as part of the view name:
68+
69+
```bash
70+
php artisan make:view dashboard.home
71+
```
72+
73+
This command will create a home.blade.php view within the `resources/views/dashboard` directory.
74+
75+
76+
## Step 4: Routes defined
77+
78+
Your provided routes are attempting to define routes in Laravel, pointing to specific controller actions. Here's an explanation of the routes you've written:
79+
80+
- Route for the Home Controller:
81+
```bash
82+
Route::get('/', [App\Http\Controllers\HomeController::class, 'index']);
83+
```
84+
- Route for the Dashboard Home Controller:
85+
86+
```bash
87+
Route::get('/dashboard', [App\Http\Controllers\Dashboard\HomeController::class, 'dashboard']);
88+
```
89+
Make sure you have the corresponding controllers and methods created:
90+
91+
- For the HomeController, there should be a file at `app/Http/Controllers/HomeController.php` with an index method.
92+
93+
For the `Dashboard\HomeController` there should be a file at
94+
95+
- app/Http/Controllers/Dashboard/HomeController.php with a dashboard method.
96+
97+
Also, ensure that the controllers are correctly namespaced. If your controllers are not in the default namespace, you should adjust the use statement at the top of your routes file accordingly.
98+
99+
Here's an example of how the controllers might be structured:
100+
101+
```bash
102+
// HomeController.php
103+
namespace App\Http\Controllers;
104+
105+
class HomeController extends Controller
106+
{
107+
public function index()
108+
{
109+
#/yourproject/config/layout-assets.php
110+
# You can add more as per your requirement
111+
# ex addWebAsset(['home', '', '']);
112+
addWebAsset(['home']);
113+
return view('home');
114+
}
115+
}
116+
117+
// Dashboard/HomeController.php
118+
namespace App\Http\Controllers\Dashboard;
119+
120+
class HomeController extends Controller
121+
{
122+
public function dashboard()
123+
{
124+
#/yourproject/config/layout-assets.php
125+
# You can add more as per your requirement
126+
# ex addVendors(['demo', '', '']);
127+
addVendors(['demo']);
128+
return view('dashboard.home');
129+
}
130+
}
131+
```
132+
133+
## Step 5: Use layout
134+
- Then, you can use this component in your `home.blade.php` or `dashboard/home.blade.php` view:
135+
### Front-End Layout (x-web-app-layout)
136+
137+
```bash
138+
<!-- resources/views/home.blade.php -->
139+
<x-web-app-layout>
140+
<h1>Front-End 👋</h1>
141+
</x-web-app-layout>
142+
```
143+
### Dashboard Layout (x-app-layout)
144+
145+
```bash
146+
<!-- resources/views/dashboard/home.blade.php -->
147+
<x-web-app-layout>
148+
<h1>Dashboard 👋</h1>
149+
</x-web-app-layout>
150+
```
151+
152+
153+
154+
155+
156+
157+
158+
40159
41160
42161

0 commit comments

Comments
 (0)