You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| The middleware should enable session and cookies support in order for the Log Viewer to work.
111
-
| The 'web' middleware will be applied automatically if empty.
112
-
|
113
-
*/
114
-
115
-
'middleware' => ['web'],
116
-
```
117
-
118
-
## Authorization
119
-
120
-
Several things can be configured to have different access based on the user logged in, or the log file in action.
121
-
122
-
Here are the permissions and how to set them up.
123
-
124
-
### Authorizing Log Viewer access
125
-
126
-
You can limit who has access to the Log Viewer in several ways.
127
-
128
-
#### Via "auth" callback
129
-
You can limit access to the Log Viewer by providing a custom authorization callback to the `LogViewer::auth()` method within your `AppServiceProvider`, like so:
130
-
131
-
```php
132
-
use Opcodes\LogViewer\Facades\LogViewer;
133
-
134
-
/**
135
-
* Bootstrap any application services.
136
-
*
137
-
* @return void
138
-
*/
139
-
public function boot()
140
-
{
141
-
LogViewer::auth(function ($request) {
142
-
// return true to allow viewing the Log Viewer.
143
-
});
144
-
145
-
// Here's an example:
146
-
LogViewer::auth(function ($request) {
147
-
return $request->user()
148
-
&& in_array($request->user()->email, [
149
-
// 'john@example.com',
150
-
]);
151
-
});
152
-
}
153
-
```
154
-
155
-
#### Via "viewLogViewer" gate
156
-
157
-
Another easy way to limit access to the Log Viewer is via [Laravel Gates](https://laravel.com/docs/9.x/authorization#gates). Just define a `viewLogViewer` authorization gate in your `App\Providers\AuthServiceProvider` class:
158
-
159
-
```php
160
-
use App\Models\User;
161
-
use Illuminate\Support\Facades\Gate;
162
-
163
-
/**
164
-
* Register any authentication / authorization services.
165
-
*
166
-
* @return void
167
-
*/
168
-
public function boot()
169
-
{
170
-
$this->registerPolicies();
171
-
172
-
Gate::define('viewLogViewer', function (?User $user) {
173
-
// return true if the user is allowed access to the Log Viewer
174
-
});
175
-
}
176
-
```
177
-
178
-
#### Via middleware
179
-
180
-
You can easily add [authentication](https://laravel.com/docs/9.x/authentication#protecting-routes) to log viewing routes using popular `auth` middleware in the `config/log-viewer.php`.
181
-
182
-
If your application doesn't use the default authentication solutions, you can use the `auth.basic`[HTTP Basic Authentication](https://laravel.com/docs/9.x/authentication#http-basic-authentication) middleware.
183
-
184
-
_**Note:** By default, the `auth.basic` middleware will assume the email column on your users database table is the user's "username"._
| The middleware should enable session and cookies support in order for the Log Viewer to work.
193
-
| The 'web' middleware will be applied automatically if empty.
194
-
|
195
-
*/
196
-
197
-
'middleware' => ['web', 'auth'],
198
-
```
199
-
200
-
For authorization using Spatie permissions [see this discussion](https://github.com/opcodesio/log-viewer/discussions/16)
201
-
202
-
### Authorizing log file download
203
-
204
-
You can limit the ability to download log files via [Laravel Gates](https://laravel.com/docs/9.x/authorization#gates). Just define a `downloadLogFile` authorization gate in your `App\Providers\AuthServiceProvider` class:
205
-
206
-
```php
207
-
use App\Models\User;
208
-
use Opcodes\LogViewer\LogFile;
209
-
use Illuminate\Support\Facades\Gate;
210
-
211
-
/**
212
-
* Register any authentication / authorization services.
213
-
*
214
-
* @return void
215
-
*/
216
-
public function boot()
217
-
{
218
-
$this->registerPolicies();
219
-
220
-
Gate::define('downloadLogFile', function (?User $user, LogFile $file) {
221
-
// return true if the user is allowed to download the specific log file.
222
-
});
223
-
}
224
-
```
225
-
226
-
#### Authorizing folder downloads
227
-
228
-
You can also limit whether whole folders can be downloaded by defining a `downloadLogFolder` authorization gate:
229
-
230
-
```php
231
-
use Opcodes\LogViewer\LogFolder;
232
-
233
-
//...
234
-
235
-
Gate::define('downloadLogFolder', function (?User $user, LogFolder $folder) {
236
-
// return true if the user is allowed to download the whole folder.
237
-
});
238
-
```
239
-
240
-
**NOTE:** Individual file permissions are also checked before downloading them, to avoid accidental downloads of protected log files.
241
-
242
-
### Authorizing log file deletion
243
-
244
-
You can limit the ability to delete log files via [Laravel Gates](https://laravel.com/docs/9.x/authorization#gates). Just define a `deleteLogFile` authorization gate in your `App\Providers\AuthServiceProvider` class:
245
-
246
-
```php
247
-
use App\Models\User;
248
-
use Opcodes\LogViewer\LogFile;
249
-
use Illuminate\Support\Facades\Gate;
250
-
251
-
/**
252
-
* Register any authentication / authorization services.
253
-
*
254
-
* @return void
255
-
*/
256
-
public function boot()
257
-
{
258
-
$this->registerPolicies();
259
-
260
-
Gate::define('deleteLogFile', function (?User $user, LogFile $file) {
261
-
// return true if the user is allowed to delete the specific log file.
262
-
});
263
-
}
264
-
```
265
-
266
-
#### Authorizing folder deletion
267
-
268
-
You can also limit whether whole folders can be deleted by defining a `deleteLogFolder` authorization gate:
269
-
270
-
```php
271
-
use Opcodes\LogViewer\LogFolder;
272
-
273
-
//...
274
-
275
-
Gate::define('deleteLogFolder', function (?User $user, LogFolder $folder) {
276
-
// return true if the user is allowed to delete the whole folder.
277
-
});
278
-
```
279
-
280
-
**NOTE:** Individual file permissions are also checked before deleting them, to avoid accidental deletion of protected log files.
281
-
282
-
### Disabling Log Viewer
283
-
284
-
To disable web access to the Log Viewer, just add an environment variable to your `.env` file:
285
-
286
-
```env
287
-
LOG_VIEWER_ENABLED=false
288
-
```
71
+
Please visit the **[Log Viewer Docs](https://log-viewer.opcodes.io/docs)** to learn about configuring Log Viewer to your needs.
0 commit comments