Laravel惯性反应-通过一个道具



我安装了breeze + react入门工具包。此外,获得了空间权限,并播种了一些角色,用户等。

我做了一个中间件来根据角色重定向用户,还做了一个特定于某个角色的仪表板页面。一切都很好,除了我似乎不能传递变量到react视图-开发工具显示我一个'未定义'的错误基本上。

应用程序/Http/中间件/CheckUserRole.php

<?php
namespace AppHttpMiddleware;
use Closure;
use IlluminateHttpRequest;
use IlluminateSupportFacadesAuth;
class CheckUserRole
{
/**
* Handle an incoming request.
*
* @param  IlluminateHttpRequest  $request
* @param  Closure(IlluminateHttpRequest): (IlluminateHttpResponse|IlluminateHttpRedirectResponse)  $next
* @return IlluminateHttpResponse|IlluminateHttpRedirectResponse
*/
public function handle(Request $request, Closure $next, ...$guards)
{
$user = Auth::user();
if ($user->hasRole('BankAdmin')) {
return redirect('/admin/dashboard');
}
if ($user->hasRole('BankUser')) {
return redirect('/user/dashboard');
}
return redirect('/');
}
}

in my routes/web.php

Route::get('/', function () {
return Inertia::render('Welcome', [
'canLogin' => Route::has('login'),
'canRegister' => Route::has('register'),
'laravelVersion' => Application::VERSION,
'phpVersion' => PHP_VERSION,
]);
});
Route::get('/dashboard', function () {
return Inertia::render('Dashboard',
);
})->middleware(['auth', 'verified', 'checkrole'])->name('dashboard');
Route::get('/user/dashboard', UserDashboardController::class);
require __DIR__ . '/auth.php'; 

应用程序/Http/控制器/UserDashboardController.php

<?php
namespace AppHttpControllers;
use InertiaInertia;
use IlluminateHttpRequest;
class UserDashboardController extends Controller
{
/**
* Return all users.
*
* @return InertiaResponse
*/
public function __invoke()
{
return Inertia::render('UserDashboard', [
'message' => 'You are logged in as BankUser',
]);
}
}

资源/js/页面/UserDashboard.jsx

import React from 'react';
import Authenticated from '@/Layouts/Authenticated';
import {Head} from '@inertiajs/inertia-react';
export default function UserDashboard(props) {
return (
<Authenticated
auth={props.auth}
errors={props.errors}
message={props.message}
header={<h2 className="font-semibold text-xl text-gray-800 leading-tight">Dashboard</h2>}
>
<Head title="User Dashboard"/>
<div className="py-12">
<div className="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div className="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div className="p-6 bg-white border-b border-gray-200">You're logged in - BankUser!{message} </div>
</div>
</div>
</div>
</Authenticated>
);
}

我做错了什么?

为什么消息未定义?

解决。{道具。导出默认函数UserDashboard({auth, errors, message}) {

相关内容

  • 没有找到相关文章

最新更新