8000 UserGuest package implementation · mdbootstrap/adminlte-laravel@8a89c1f · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a89c1f

Browse files
committed
UserGuest package implementation
1 parent 912a708 commit 8a89c1f

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

src/GuestUser.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Acacha\AdminLTETemplateLaravel;
4+
5+
use Illuminate\Contracts\Auth\MustVerifyEmail;
6+
use Illuminate\Foundation\Auth\User as Authenticatable;
7+
use Illuminate\Notifications\Notifiable;
8+
9+
class GuestUser extends Authenticatable
10+
{
11+
use Notifiable;
12+
13+
/**
14+
* The attributes that are mass assignable.
15+
*
16+
* @var array
17+
*/
18+
protected $fillable = [
19+
'name', 'email', 'password',
20+
];
21+
22+
23+
/**
24+
* The attributes that should be hidden for arrays.
25+
*
26+
* @var array
27+
*/
28+
protected $hidden = [
29+
'password', 'remember_token',
30+
];
31+
32+
/**
33+
* The attributes that should be cast to native types.
34+
*
35+
* @var array
36+
*/
37+
protected $casts = [
38+
'email_verified_at' => 'datetime',
39+
];
40+
}

src/Http/Middleware/GuestUser.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Acacha\User\Http\Middleware;
4+
5+
use Closure;
6+
7+
/**
8+
* Class GuestUser
9+
* @package Acacha\User\Http\Middleware
10+
*/
11+
class GuestUser
12+
{
13+
/**
14+
* Handle an incoming request.
15+
*
16+
* @param \Illuminate\Http\Request $request
17+
* @param \Closure $next
18+
* @return mixed
19+
*/
20+
public function handle($request, Closure $next)
21+
{
22+
view()->share('signedIn', auth()->check());
23+
view()->share('user', auth()->user() ?: new \Acacha\User\GuestUser);
24+
25+
return $next($request);
26+
}
27+
}

src/Providers/AdminLTETemplateServiceProvider.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
namespace Acacha\AdminLTETemplateLaravel\Providers;
44

5+
<<<<<<< Updated upstream
56
use Acacha\AdminLTETemplateLaravel\Facades\AdminLTE;
7+
=======
8+
use Illuminate\Routing\Router;
9+
use Illuminate\Support\ServiceProvider;
10+
use Acacha\User\Http\Middleware\GuestUser;
11+
>>>>>>> Stashed changes
612
use Creativeorange\Gravatar\Facades\Gravatar;
7-
use Creativeorange\Gravatar\GravatarServiceProvider;
813
use Illuminate\Console\DetectsApplicationNamespace;
9-
use Illuminate\Support\ServiceProvider;
14+
use Acacha\AdminLTETemplateLaravel\Facades\AdminLTE;
15+
use Creativeorange\Gravatar\GravatarServiceProvider;
1016

1117
/**
1218
* Class AdminLTETemplateServiceProvider.
@@ -71,8 +77,10 @@ class_alias(Gravatar::class, 'Gravatar');
7177
/**
7278
* Bootstrap the application services.
7379
*/
74-
public function boot()
80+
public function boot(Router $router)
7581
{
82+
$router->pushMiddlewareToGroup('web', GuestUser::class);
83+
7684
if (config('adminlte.install_routes', true)) {
7785
$this->defineRoutes();
7886
}

0 commit comments

Comments
 (0)
0