use helper to access user and customer
This commit is contained in:
parent
8b86d42793
commit
c40f743d69
|
|
@ -8,7 +8,7 @@ use Illuminate\View\Component;
|
||||||
class Header extends Component
|
class Header extends Component
|
||||||
{
|
{
|
||||||
public array $links = [];
|
public array $links = [];
|
||||||
private AdminUser $adminUser;
|
private ?AdminUser $adminUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new component instance.
|
* Create a new component instance.
|
||||||
|
|
@ -17,7 +17,7 @@ class Header extends Component
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->adminUser = auth()->user();
|
$this->adminUser = current_user();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class Sidebar extends Component
|
||||||
{
|
{
|
||||||
$this->adminName = admin_name();
|
$this->adminName = admin_name();
|
||||||
$this->routeNameWithPrefix = request()->route()->getName();
|
$this->routeNameWithPrefix = request()->route()->getName();
|
||||||
$this->adminUser = auth(AdminUser::AUTH_GUARD)->user();
|
$this->adminUser = current_user();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -135,9 +135,9 @@ function equal_route($routeName): bool
|
||||||
/**
|
/**
|
||||||
* 获取后台当前登录用户
|
* 获取后台当前登录用户
|
||||||
*
|
*
|
||||||
* @return Authenticatable|null
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function current_user(): ?Authenticatable
|
function current_user(): ?AdminUser
|
||||||
{
|
{
|
||||||
return auth()->guard(AdminUser::AUTH_GUARD)->user();
|
return auth()->guard(AdminUser::AUTH_GUARD)->user();
|
||||||
}
|
}
|
||||||
|
|
@ -145,9 +145,9 @@ function current_user(): ?Authenticatable
|
||||||
/**
|
/**
|
||||||
* 获取前台当前登录客户
|
* 获取前台当前登录客户
|
||||||
*
|
*
|
||||||
* @return Authenticatable|null
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function current_customer(): ?Authenticatable
|
function current_customer(): ?Customer
|
||||||
{
|
{
|
||||||
return auth()->guard(Customer::AUTH_GUARD)->user();
|
return auth()->guard(Customer::AUTH_GUARD)->user();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,23 +13,21 @@ namespace Beike\Shop\Http\Controllers\Account;
|
||||||
|
|
||||||
use Beike\Models\Customer;
|
use Beike\Models\Customer;
|
||||||
use Beike\Repositories\CustomerRepo;
|
use Beike\Repositories\CustomerRepo;
|
||||||
use Beike\Shop\Http\Controllers\Controller;
|
|
||||||
use Beike\Shop\Http\Requests\EditRequest;
|
|
||||||
use Beike\Shop\Http\Requests\ForgottenRequest;
|
|
||||||
use http\Env\Request;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use function auth;
|
use Beike\Shop\Http\Requests\EditRequest;
|
||||||
use function view;
|
use Beike\Shop\Http\Controllers\Controller;
|
||||||
|
use Beike\Shop\Http\Requests\ForgottenRequest;
|
||||||
|
|
||||||
class AccountController extends Controller
|
class AccountController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 个人中心首页
|
* 个人中心首页
|
||||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$data = auth(Customer::AUTH_GUARD)->user()->toArray();
|
$data = current_customer()->toArray();
|
||||||
$data['avatar'] = image_resize($data['avatar']);
|
$data['avatar'] = image_resize($data['avatar']);
|
||||||
return view('account/account', $data);
|
return view('account/account', $data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class EditController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$customer = auth(Customer::AUTH_GUARD)->user();
|
$customer = current_customer();
|
||||||
$data['customer'] = $customer;
|
$data['customer'] = $customer;
|
||||||
return view('account/edit', $data);
|
return view('account/edit', $data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class AccountSidebar extends Component
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->customer = auth(Customer::AUTH_GUARD)->user();
|
$this->customer = current_customer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<a href="#" class="nav-link dropdown-toggle px-2" data-bs-toggle="dropdown">
|
<a href="#" class="nav-link dropdown-toggle px-2" data-bs-toggle="dropdown">
|
||||||
<img src="http://dummyimage.com/100x100" class="avatar img-fluid rounded-circle me-1">
|
<img src="http://dummyimage.com/100x100" class="avatar img-fluid rounded-circle me-1">
|
||||||
<span class="text-dark ml-2">{{ auth()->user()->name }}</span>
|
<span class="text-dark ml-2">{{ current_user()->name }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuLink">
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuLink">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue