标签: inertiajs

如何通过 Laravel 8惯性中的模型访问关系

我在用户表和区域表之间有一对多的关系,当我返回配置文件数据时,我从用户表中获取area_id,我需要使用模型获取区域名称。有没有办法在个人资料视图中获取区域名称?我尝试在 show.vue 中调用模型函数,但它不起作用。

用户.php

 public function area()
    {
        return $this->belongsTo(Area::class);
    }
Run Code Online (Sandbox Code Playgroud)

区域.php

 public function users()
    {
        return $this->hasMany(User::class);
    }
Run Code Online (Sandbox Code Playgroud)

显示.vue

<template>
    <app-layout>
        <template #header>
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                Profile
            </h2>
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                Area : 
            </h2>
        </template>

        <div>
            <div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">
                <div v-if="$page.props.jetstream.canUpdateProfileInformation">
                    <update-profile-information-form :user="$page.props.user" />

                    <jet-section-border />
                </div>

                <div v-if="$page.props.jetstream.canUpdatePassword">
                    <update-password-form class="mt-10 sm:mt-0" />

                    <jet-section-border />
                </div>

                <div v-if="$page.props.jetstream.canManageTwoFactorAuthentication">
                    <two-factor-authentication-form class="mt-10 sm:mt-0" />

                    <jet-section-border />
                </div>

                <logout-other-browser-sessions-form :sessions="sessions" class="mt-10 sm:mt-0" />

                <template v-if="$page.props.jetstream.hasAccountDeletionFeatures"> …
Run Code Online (Sandbox Code Playgroud)

inertiajs vuejs2 laravel-8

8
推荐指数
1
解决办法
4668
查看次数

使用 Vue 3 在 InertiaJS 中定义全局组件

我正在尝试构建一个应用程序作为Laravel 8.38 - InertiaJS 0.8.4Vue 3的前端堆栈。

我有多个布局,需要将其全局注册为Vue组件,以便我可以在应用程序中的任何地方使用它。我无法这样做,我的代码:

import { createApp, h } from 'vue';
import { App as InertiaApp, plugin as InertiaPlugin } from '@inertiajs/inertia-vue3';

const el = document.getElementById('app');

const app = createApp({
    render: () =>
        h(InertiaApp, {
            initialPage: JSON.parse(el.dataset.page),
            resolveComponent: (name) => require(`./../Pages/${name}`).default,
        }),
})
    .mixin({ methods: { route } })
    .use(InertiaPlugin);

app.component('app-market', () => import('./../layouts/AppMarketLayout')); //trying to import layout

app.mount(el);
Run Code Online (Sandbox Code Playgroud)

在页面内部,我尝试调用此布局组件:

<template>
    <div>
        <app-market-layout></app-market-layout>
    </div>
</template>
Run Code Online (Sandbox Code Playgroud)

无法获取,控制台中没有错误。

inertiajs laravel vue.js vuejs3

7
推荐指数
1
解决办法
6658
查看次数

Vue3/Inertia 无法解析组件

我有一个使用 VILT 堆栈(Vue、Inertia、Laravel、Tailwind)构建的应用程序。我有一些类似的组件cards可以在应用程序中的任何地方使用。因为我不想每次构建一个在某些目录中注册组件的函数时都手动导入这些组件:

/**
 * Register components from the ./components and ./components/core
 * directories. This way these components don't have to be imported
 * manually every time.
 *
 * @param {Vue instance} app
 */
function registerGlobalComponents (app) {
  const requireComponent = require.context(
    './components' || './components/core',
    true,
    /\.vue$/
  );

  for (const file of requireComponent.keys()) {
    const componentConfig = requireComponent(file);
    const name = file
      .replace(/index.js/, '')
      .replace(/^\.\//, '')
      .replace(/\.\w+$/, '');
    const componentName = upperFirst(camelCase(name));

    app.component(componentName,
      componentConfig.default || componentConfig);
  }
} …
Run Code Online (Sandbox Code Playgroud)

inertiajs vue.js vuejs3

7
推荐指数
1
解决办法
4099
查看次数

使用 Laravel Vue Inertia 堆栈中的数据重定向路由

在我的控制器中我有

public function store(Request $request)
    {
        $postData = $this->validate($request, [
            'name' => 'required',
            'status' => 'required | boolean'
        ]);

        Room::create([
            'name' => $postData['name'],
            'active' => $postData['status'],
        ]);

        $message = "Room Added";

        return redirect::route('rooms.index', ['msg' => $message]);
    }
Run Code Online (Sandbox Code Playgroud)

我在道具中使用了“msg”

props:['rooms','errors','msg']
Run Code Online (Sandbox Code Playgroud)

但是对于 {{msg}} 给出了未定义的并且没有任何消息。

php inertiajs laravel vue.js

7
推荐指数
1
解决办法
2万
查看次数

如何在每次滚动时禁用osx中的多滚动效果和一次火焰滚动事件

我需要像jquery.fullPage那样组织导航:当我滚动一次时 - 我转到下一部分.

我尝试使用jquery.mousewheel,但它在带有触摸板或触控板或APPLE Magic Mouse的MacOS中失败:它每个滚动滚动多个幻灯片.

我试图使用这个解决方案:https://github.com/jquery/jquery-mousewheel/issues/36#issuecomment-67648897

它在Chrome中运行良好,但它不在FF中并且在Safari中存在错误.

这是问题的简单演示:http: //jsfiddle.net/ss5LueLx/13/

$slider.on('mousewheel', function(event) {
    if (event.deltaY>0) {
        slider.prevSlide();
    } else {
        slider.nextSlide();
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript macos jquery mousewheel inertiajs

6
推荐指数
1
解决办法
972
查看次数

如何为 Laravel Fortify + Inertia + vue 添加角色和权限?

我的项目使用 laravel fortify,惯性与 vue。我必须添加基于角色的权限(就像 spatie 权限包一样)。我对于强化和惯性还是一个初学者。但我有 spatie 包的经验。我对如何添加角色和权限进行强化感到困惑。目前我计划创建像 spatie 包 has 这样的表结构(角色、权限、roles_has_permissions 等)。是否有每个构建包或更好的方法来实现角色和权限?并在 vue 文件中使用“@can”?谢谢。

编辑

大家好,这是我目前所做的(我现在正在使用这个)。它正在工作,但仍需要一些改进,(任何更好的解决方案我真的很感激)

1)照常安装和配置 spatie/laravel-permission

2)使用seeder向表添加预定义的权限和角色

  1. 在用户模型中创建函数来获取权限数组列表

    // user model function
    public function getPermissionArray()
     {
         return $this->getAllPermissions()->mapWithKeys(function($pr){
             return [$pr['name'] => true];
         });
    
     }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 并将该功能添加到惯性中间件中

// user model function
public function getPermissionArray()
 {
     return $this->getAllPermissions()->mapWithKeys(function($pr){
         return [$pr['name'] => true];
     });

 }
Run Code Online (Sandbox Code Playgroud)

现在$page.props.auth.can可以全球访问

  1. 在vue文件中添加权限检查
   <div class="row">
              <div class="col-sm-12 col-md-6" v-if="$page.props.auth.can['user_create']">
                <inertia-link
                  class="btn btn-primary"
                  :href="$route('admin.user.create')"
                  >Create New
                </inertia-link>
              </div>
   </div>
Run Code Online (Sandbox Code Playgroud)

inertiajs laravel laravel-fortify

6
推荐指数
2
解决办法
9465
查看次数

如何在 Laravel-8 和 InertiaJs 中向服务器发出 POST 请求时保留浏览器中当前的 GET url

我在 Laravel 8 中使用 Inertia JS,并向服务器发出以下 POST 请求。问题是浏览器 URL 也会通过 POST 请求进行更新,这在某些情况下可能是预期行为,但我想在浏览器中保留实际的 GET 请求,尽管使用多个 Laravel 路由向服务器发送不同类型的请求。

this.$inertia.put(`/task/${task_id}`, {order, category_id});

this.$inertia.visit(`/task/${task_id}`, {
    method: 'put',
    data: {order, category_id},
    only: ['categories', 'msg'],
    replace: true,
    preserveState: true,
    preserveScroll: true,
});
                
Run Code Online (Sandbox Code Playgroud)

有人知道如何在使用 Inertia JS 向服务器发送 POST 请求的同时保留浏览器中现有的 GET URL 吗?

javascript inertiajs laravel vue.js laravel-8

6
推荐指数
1
解决办法
1718
查看次数

在我的 Inertia laravel 应用程序中获取 View [app] not found 错误

我正在尝试在我的 laravel 应用程序中使用惯性。我的应用程序不需要 jetstream,所以我不会使用它。所以我去了惯性网站https://inertiajs.com/来安装它,但我不确定我是否正确地安装了它。

我的页面上出现的错误是

查看[应用程序]未找到。

这就是我的 ProductController 中的内容

public function index()
{
    return Inertia::render('components/products/Index');
}
Run Code Online (Sandbox Code Playgroud)

这是我的 Index.vue

<template>
    <div>
        <h1>Welcome</h1>
        <p>Hello, welcome to your first Inertia app!</p>
    </div>
</template>

<script>
    export default {
        components: {

        },
        props: {

        },
    }
</script>
Run Code Online (Sandbox Code Playgroud)

在我的 app.blade.php 中

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">

    <title>Admin</title>

    <link rel="stylesheet" href="/vendor/adminlte/plugins/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="/css/style.css">

</head>
<body class="hold-transition sidebar-mini">
    <div class="wrapper">

    <!-- Navbar -->
    <nav class="main-header navbar …
Run Code Online (Sandbox Code Playgroud)

inertiajs laravel laravel-8

6
推荐指数
1
解决办法
6246
查看次数

混合内容:“domain”处的页面是通过 HTTPS 加载的,但请求了不安全的 XMLHttpRequest 端点

我一直在尝试解决仅在生产中发生的错误。当我尝试create新的数据库条目时,会引发以下错误:

Mixed Content: The page at 'https://strong-moebel.art/admin/gallerie/neu' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://strong-moebel.art/admin/gallerie'. This request has been blocked; the content must be served over HTTPS.
Run Code Online (Sandbox Code Playgroud)
Uncaught (in promise) Error: Network Error
    at wh (main.750d1ea1.js:4:96980)
    at s.onerror (main.750d1ea1.js:5:1837)
Run Code Online (Sandbox Code Playgroud)

其他一切都有效,包括edit条目的方法。我正在使用一个resource controller. create方法使用惯性form.postedit方法使用其form.put(如果相关的话)。

我一直在尝试使用以下提供的解决方案来调试此问题:

  1. 混合内容问题 - 内容必须以 HTTPS 形式提供
  2. 混合内容(laravel)

基本上人们都说要添加:

if (App::environment('production')) {
    URL::forceScheme('https');
}
Run Code Online (Sandbox Code Playgroud)

按照boot()你的方法AppServiceProvider.php。我已经这样做了,但错误仍然出现。我想知道这是否是一个惯性问题。

在服务器上,我尝试过:

APP_ENV=production
APP_URL=http://localhost
APP_URL=https://localhost …
Run Code Online (Sandbox Code Playgroud)

ssl inertiajs laravel vue.js vuejs3

6
推荐指数
2
解决办法
2万
查看次数

我应该如何使用 Inertia 通过 Laravel 和 Vue 支持我的项目的本地化?

我是 Laravel 的中级。我在 Laravel 中为我的客户发布了一些项目。

我使用 Inertia 与Laravel 和 Vue启动了一个项目。我使用了 Laravel 10 的入门工具包以及 Breeze 和 vue。当我设置项目并配置各种内容时,我浏览了Laravel 10 通过 artisan 命令发布的lang目录。

我陷入本地化困境。我只知道如何使用 Laravel 进行翻译和本地化。这是 Laravel 和 vue 对我来说绝对是新的。

我研究了如何实现本地化,但发现 3 到 4 年前的资源没有正确的实现,需要付出大量的努力,甚至缺乏 Laravel 的一些翻译功能。

正如我所说,我使用了入门工具包,并使用 artisan 命令发布了 lang 目录。我尝试更改failed位于auth.php. lang/en/auth.php通过输入错误的凭据进行检查,发现我的更新消息有误。但是现在我创建了hi印度印地语的目录。我复制auth.php并翻译了该文件的所有三条消息。我更改了默认区域设置config/app.php使用错误的凭据再次进行了测试。这次它没有显示我的印地语翻译。它再次显示相同的英文翻译。我再次尝试更改英语翻译行,它显示了更新的行。

我检查了这些文件组件以查找翻译源,我意识到它只是显示了一条错误消息form。我不知道为什么当我更改默认区域设置时它没有获取我的翻译文件。

我正在寻找一种更简单、更有效的方式在Laravel 中使用 Vue 和 Inertia进行本地化。

经过大量研究,我找到了这个包https://github.com/rmariuzzo/Laravel-JS-Localization

请让我知道它是否会以有效的方式完成这项工作,或者Laravel 中的 …

php localization inertiajs laravel vue.js

6
推荐指数
1
解决办法
2236
查看次数