我想分享一些我发现的东西,因为那里没有太多信息(我找不到)。带有 Jetstream Inertia 的 Laravel 8 有一些共享对象,例如用户、当前路由……您可以使用 $page 变量在组件中访问它们。我需要添加一个菜单数组作为全局变量,但无法弄清楚,即使在官方 Inertia 文档中找到了一些信息。只是在 Laravel Jetstream 中有所不同。
直到我找到了 Laravel Jetstream 的共享数据中间件(ShareInertiaData),我才知道怎么做。
这是:
<?php
namespace App\Http\Middleware;
use Inertia\Inertia;
class ShareInertiaCustomData
{
public function handle($request, $next)
{
Inertia::share([
'menu' => config('menu'),
]);
return $next($request);
}
}
Run Code Online (Sandbox Code Playgroud)
protected $middlewareGroups = [
'web' => [
...
\App\Http\Middleware\ShareInertiaCustomData::class,
],
];
Run Code Online (Sandbox Code Playgroud)
我希望这会有所帮助,没有其他人需要花费数小时来解决这个问题。
global-variables shared-data inertiajs laravel laravel-jetstream
我开始使用 Laravel 8 构建一个 Web 应用程序。我注意到 Laravel 8 中的很多事情都发生了变化,包括身份验证。现在,我正在尝试使用 Jetstream 进行身份验证。
我已运行以下命令将其集成到应用程序中。
composer require laravel/jetstream
php artisan jetstream:install inertia
npm install && npm run dev
Run Code Online (Sandbox Code Playgroud)
当我去/register路线时,我可以看到包含姓名、电子邮件、密码和密码确认字段的注册表。我想要做的是我想添加另一个名为“公司”的字段,我想对其应用自定义验证规则。
我在 Jetstream 文档中发现,我可以在 JetstreamServiceProvider 类的引导方法中自定义身份验证过程,如下所示。
Fortify::authenticateUsing(function (Request $request) {
});
Run Code Online (Sandbox Code Playgroud)
但不适用于注册。如何自定义注册过程添加新字段和应用自定义验证规则?
Laravel 8 和 jetstream,真的是新的吗?
我只是尝试在 fortify 中安装和播放它,但我真的不明白为什么我的个人资料照片没有显示图片。
更新配置文件信息表单
<!-- Current Profile Photo -->
<div class="mt-2" x-show="! photoPreview">
<img src="{{ $this->user->profile_photo_url }}"
alt="{{ $this->user->name }}"
class="rounded-full h-20 w-20 object-cover">
</div>
Run Code Online (Sandbox Code Playgroud)
.Env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:6IJbdi+QYczKeLT7yOw3OgPsHucXn1KxVUb27hTQKpU=
APP_DEBUG=true
APP_URL=http://127.0.0.1:8000
Run Code Online (Sandbox Code Playgroud)
配置/文件系统
'public' => [
'driver' => 'local',
'root' => storage_path('/public/storage'),
'url' => env('APP_URL').'/public/storage/',
'visibility' => 'public',
],
Run Code Online (Sandbox Code Playgroud) 如果我已经有一个现有的 Laravel Jetstream (Inertia) 项目,并且在没有该--teams选项的情况下安装,鉴于我已经在应用程序中创建了多个控制器、模型、迁移和其他自定义项,是否有办法返回并安装对团队的支持?
**我在 laravel 8 上安装了 livewire 、laravel mix 和 jetstream 。但是 Jetsream 的 css 和 js 不起作用,并在标头中显示一条消息 ' @vite(['resources/css/app.css', 'resources/js/ app.js']) ' **
应用程序.blade.php
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap">
<!-- Styles -->
@livewireStyles
<!-- Scripts -->
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body class="font-sans antialiased">
<x-jet-banner />
<div class="min-h-screen bg-gray-100">
@livewire('navigation-menu')
<!-- Page Heading -->
@if (isset($header))
<header class="bg-white shadow">
<div …Run Code Online (Sandbox Code Playgroud) 我在 Laravel 8 中很好地安装了 Laravel JetStream 和 Spatie 的 laravel-permission。
\n我可以在注册过程中为用户分配角色
\n$user->assignRole('visitor');\nreturn $user;\nRun Code Online (Sandbox Code Playgroud)\n并可以通过我在播种器 fil\xc3\xa9s run 方法中分配给角色的权限来限制用户仪表板上的可用菜单项:
\nPermission::create(['name' => 'access profile']);\nPermission::create(['name' => 'access logout']);\n\n$visitor = Role::create(['name' => 'visitor']);\n$visitor->givePermissionTo('access profile');\nRun Code Online (Sandbox Code Playgroud)\n并通过视图中的 can 指令,例如:
\n@can('access profile')\n<!-- Account Management -->\n<div class="block px-4 py-2 text-xs text-gray-400">\n {{ __('Manage Account') }}\n</div>\n\n<x-jet-dropdown-link href="{{ route('profile.show') }}">\n {{ __('Profile') }}\n</x-jet-dropdown-link>\n@endcan\nRun Code Online (Sandbox Code Playgroud)\n因此,我可以根据角色隐藏菜单项,但不幸的是,我仍然可以通过知道确切的 URL 直接访问该功能。
\n我想我必须编写一个中间件来限制对某些功能的访问,但具体怎么做呢?
\n在此堆栈中处理此问题的正确且可接受的方法是什么?
\n谢谢!\nArmand\n所以一切看起来都很好,但是(!)
\n如何禁止直接访问隐藏项目?我想在这种情况下,路由是由 sainttum 控制的,而角色和权限是由 Spatie 的包控制的。
\n是否可以将两者联系起来?
\n谢谢!
\nlaravel laravel-permission laravel-sanctum laravel-jetstream laravel-fortify
我正在尝试在最新的 Laravel 版本 (8) 上安装 Vuetify,但我无法做到。即使控制台没有显示任何错误,它似乎也不起作用。
那是我的资源/插件/vuetify.js
import Vue from 'vue'
// import Vuetify from 'vuetify'
import Vuetify from 'vuetify/lib'
// import 'vuetify/dist/vuetify.min.css'
Vue.use(Vuetify)
const opts = {}
export default new Vuetify(opts)
Run Code Online (Sandbox Code Playgroud)
我的webpack.mix.js:
const mix = require('laravel-mix')
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')
mix
.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
require('postcss-import'),
require('tailwindcss'),
])
.webpackConfig({
plugins: [
new VuetifyLoaderPlugin()
],
})
.browserSync('tb8.test');
Run Code Online (Sandbox Code Playgroud)
在app.js
import PortalVue from 'portal-vue';
Vue.use(InertiaApp);
Vue.use(InertiaForm);
Vue.use(PortalVue);
Vue.use(vuetify);
const app = document.getElementById('app');
new Vue({
vuetify,
render: (h) …Run Code Online (Sandbox Code Playgroud) 我过去能够成功部署 Laravel 项目。我第一次将 Laravel 8 与 Jetstream 和 Livewire 一起使用。Laravel 现在使用 Fortify 进行登录和注册身份验证。
我的本地服务器运行完美,没有任何问题。将项目部署到 Hostgator 共享托管帐户后,我的主页正确加载,并正确从数据库读取和输出数据。
但是,当我尝试访问时
mydomain.com/login/ 或 mydomain.com/login 或 mydomain.com/register/ 或 mydomain.com/register
我收到 500 错误。在这个问题的末尾,我粘贴了错误日志。
我做了以下事情:
我觉得很奇怪,我的主页加载完美,并且从数据库中获取数据也很好,因此我知道我的 .env 文件具有正确的数据库连接凭据。只有登录和注册才会抛出500错误。
我的环境文件:
APP_NAME=NameOfApp
APP_ENV=production
APP_KEY=base64:KeyGeneratedWhenProjectCreated
APP_DEBUG=false
APP_URL=http://domain
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=db_works_good
DB_USERNAME=username_works_good
DB_PASSWORD=passwordWorksGood
Run Code Online (Sandbox Code Playgroud)
这是 laravel.log (缩写为看起来重要的内容):
[2020-11-30 20:25:34] production.ERROR: The Mix manifest does not …Run Code Online (Sandbox Code Playgroud) 我找不到任何文档来解释 <template> 上的 #tags
例子:
<script setup>
import { ref } from 'vue';
import { useForm } from '@inertiajs/inertia-vue3';
import JetActionMessage from '@/Jetstream/ActionMessage.vue';
import JetButton from '@/Jetstream/Button.vue';
import JetFormSection from '@/Jetstream/FormSection.vue';
import JetInput from '@/Jetstream/Input.vue';
import JetInputError from '@/Jetstream/InputError.vue';
import JetLabel from '@/Jetstream/Label.vue';
const passwordInput = ref(null);
const currentPasswordInput = ref(null);
const form = useForm({
current_password: '',
password: '',
password_confirmation: '',
});
const updatePassword = () => {
form.put(route('user-password.update'), {
errorBag: 'updatePassword',
preserveScroll: true,
onSuccess: () => form.reset(),
onError: () …Run Code Online (Sandbox Code Playgroud) laravel ×10
inertiajs ×3
laravel-8 ×2
vue.js ×2
fortify ×1
laravel-mix ×1
shared-data ×1
tailwind-css ×1
vite ×1
vuetify.js ×1