小编IGP*_*IGP的帖子

绑定输入值未出现在请求中

我正在尝试将backAfterSaveStatus值绑定到隐藏输入,由于某种原因,提交的表单backAfterSave值为空。之后我回去再次提交表单 -backAfterSave值是1。问题出在哪里?我没有尝试过同样的事情preventsubmit()但它仍然无法正常工作。此外,我已经转储了 div,x-text并且代码在提交表单之前将隐藏输入设为 1。我做错了什么?

<form action="<...>" method="post">
    <div x-data="{
        backAfterSaveStatus: '',
        backAfterSave () {
            this.backAfterSaveStatus = '1';
            document.querySelector('form.withBackAfterSave').submit();
        }
    }">
        <input name="backAfterSave" :value="backAfterSaveStatus">
        <div>
            <span>
                <button x-on:click.prevent="backAfterSave()" type="submit">
                    Save & back
                </button>
            </span>
            <span>
                <button type="submit">
                    Save
                </button>
            </span>
        </div>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

我想要与下面相同的结果:

let buttonBackAfterSave = document.getElementById('button-back-after-save');

if (buttonBackAfterSave) {
    buttonBackAfterSave.addEventListener('click',  () => document.getElementById('input-back-after-save').value = 1);
}
Run Code Online (Sandbox Code Playgroud)

html javascript laravel alpine.js

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

How to handle the success URL on Stripe considering GET requests should be safe?

When we make a stripe checkout session we include a success url:

session = await this.stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    line_items: lineItems,
    payment_intent_data: {
        transfer_data: {
            amount: 9999999,
            destination: someaccountId,
        },
    },
    success_url: `http://localhost:4000/api/checkout/success?true&session_id={CHECKOUT_SESSION_ID}&alias_id=${aliasId}`, 
    cancel_url: `http://localhost:4000/api/checkout/canceled?session_id={CHECKOUT_SESSION_ID}`,
});
Run Code Online (Sandbox Code Playgroud)

The success URL is where stripe sends the user after a successful payment. It's a GET request since stripe is redirecting the user. Many apps using stripe will need to take actions after a successful checkout- sending an email receipt, notifications, sending paid content, updating …

get http idempotent stripe-payments

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

Laravel - 将使用 TailwindCSS 样式的视图输出为 PDF

我正在尝试从视图生成 pdf,但样式就是不出来。我尝试过使用 3 个不同的库,但结果并没有太大不同。我错过了什么吗?

view

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Test View</title>
  <link rel="stylesheet" type="text/css" media="screen" href="{{ asset('css/app.css') }}">
  <script src="{{ asset('js/app.js') }}" defer></script>
</head>
<body class="font-sans antialiased">

<div class="grid grid-cols-3">
  <div class="bg-red-200 col-span-2 h-screen"></div>
  <div class="bg-blue-200 h-screen">
    <div class="grid grid-cols-8">
      <div class="col-span-7">
        <div class="rounded-t-full w-full h-screen flex items-center justify-center bg-green-600">
          <div class="h-60 w-60 rounded-full bg-blue-500">TEST</div>
        </div>
      </div>
    </div>
  </div>
</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

appearance

在此输入图像描述


dompdf export method

protected function dompdfImplementation()
{
    $dompdf = new …
Run Code Online (Sandbox Code Playgroud)

dompdf tcpdf mpdf laravel tailwind-css

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

通过 fetch 强制使用 HTTP 缓存

我试图使用 HTTP 缓存来做一些简单的事情,但我无法让它工作。

我正在使用以下选项fetch()

fetch('test', {
        cache: 'force-cache',
        headers: {
            'Cache-Control': 'max-age=3600',
            'Pragma': 'max-age=3600', // added for redundancy
        }
    })
    .then( response => response.json() )
    .then( data     => console.log(data) )
    .catch( error   => console.error(error) )
    .finally( ()    => console.log('Done') );
Run Code Online (Sandbox Code Playgroud)

端点test只是返回一个具有以下格式的json

{
    "date": "...", /* date in 'Y-m-d H:i:s' format */
}
Run Code Online (Sandbox Code Playgroud)

我已确保响应也具有 Cache-Control 标头。当我检查响应标头时我可以看到它。

HTTP/1.1 200 好
服务器:阿帕奇
缓存控制:公共,最大年龄=3600
内容长度:30
保持活动:超时=5,最大值=94
连接:保持活动状态
内容类型:application/json;字符集=UTF-8

请求标头似乎也是正确的。

连接:保持活动状态
编译指示:最大年龄=3600
缓存控制:max-age=3600
接受: */*
Sec-Fetch-Site:同源
Sec-Fetch-Mode:cors
Sec-Fetch-Dest:空

我尝试在一分钟内一遍又一遍地运行相同的获取,期望获得相同的日期,不变,但结果总是“新的”,可以这么说。

我对 HTTP …

javascript http fetch http-caching

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

为什么 Laravel 默认通过 POST(而不是 GET)注销?

在 Laravel 应用程序的上下文中,POST 执行注销的意义是什么?POST 是否有一些安全性和/或会话特殊性?

生成的相关部分make::auth

<ul class="dropdown-menu" role="menu">
  <li>
    <a
      href="{{ url('/logout') }}"
      onclick="event.preventDefault();document.getElementById('logout-form').submit();">
      Logout
    </a>

    <form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
      {{ csrf_field() }}
    </form>
  </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-routing laravel-5

5
推荐指数
1
解决办法
2128
查看次数

如何在 Laravel Blade 中创建可搜索的选择选项表单

我正在尝试构建一个带有可搜索选项的城市选择选项表单。到目前为止,我已经构建了这个,但是所选的数据没有被保存,并且我的代码仍然缺乏搜索功能。

{!! Form::select('custom_field1', array('Delhi', 'Goa'), '1', ['class' => 'form-control', 'placeholder' => 'Select City']); !!}
Run Code Online (Sandbox Code Playgroud)

原始代码

{!! Form::select('custom_field1', array('Delhi', 'Goa'), '1', ['class' => 'form-control', 'placeholder' => 'Select City']); !!}
Run Code Online (Sandbox Code Playgroud)

php forms jquery laravel

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

Livewire - 检测到多个根元素

我正在创建一个表,其行包含在 Livewire 组件内

\n
<div class="card">\n    <div class="card-body">\n        <table class="table table-hover table-striped">\n            <thead>\n                <tr>\n                    <th>Nombre del Riesgo</th>\n                    <th>Informaci\xc3\xb3n</th>\n                    <th>Due\xc3\xb1o del Riesgo</th>\n                    <th>Costo Adicional</th>\n                    <th>Prevenci\xc3\xb3n</th>\n                </tr>\n            </thead>\n            <tbody>\n                <div>\n                    @foreach($risks as $risk)\n                        <livewire:risk-row :risk="$risk"/>\n                    @endforeach\n                </div>\n            </tbody>\n        </table>\n    </div>\n</div>\n
Run Code Online (Sandbox Code Playgroud)\n

但在行组件中,每当我更改输入或从下拉选择中选择某些内容时,该组件都不会重新渲染。

\n

我想知道为什么会发生这种情况。所以我打开控制台并看到:

\n
Livewire: Multiple root elements detected. This is not supported. See docs for more information https://laravel-livewire.com/docs/2.x/troubleshooting#root-element-issues <div wire:id=\xe2\x80\x8b"6CNMP1hiBR3Qy7IbmfbQ">\xe2\x80\x8b \xe2\x80\x8b</div>\xe2\x80\x8b\nvalue @ index.js:85\nComponent @ index.js:27\n(anonymous) @ index.js:88\nvalue @ index.js:87\n(anonymous) @ schedule:432\n
Run Code Online (Sandbox Code Playgroud)\n

这是组件刀片文件

\n
Livewire: Multiple root elements detected. This …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-livewire

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

Laravel - Ajax 调用 500(内部服务器错误)

我一直在针对我的上下文尝试本教程(https://www.youtube.com/watch?time_continue=7&v=D4ny-CboZC0),但出现此错误:

POST http://127.0.0.1:8000/transactions/fetch 500(内部服务器错误)

在此处输入图片说明

创建.blade.php

@extends('layouts.app')
@section('title', 'New Transaction')
@section('content')
<form action="/transactions" method="POST">
    <div class="row">
        <label>Item Name</label>
        <input type="text" name="item_name" id="item_name" class="form-control input-lg" placeholder="Item Name">
        <div id="itemList"></div>
        {{ csrf_field()}}
        <label>Quantity</label>
        <input type="text" name="quantity[]"  value="" placeholder="Quantity">
        {{ $errors->first('quantity')}}
    </div>
    <button type="submit" class="btn btn-primary">Complete Order</button>
    @csrf
</form>

<script type="text/javascript">
$(document).ready(function(){
    $('#item_name').keyup(function(){
        var query = $(this).val();
        if(query!=''){
            var _token = $('input[name="_token"]').val();
            console.log(_token);
            $.ajax({
                url: "{{route('autocomplete.fetch')}}",
                method: "POST",
                data: {query: query, _token:_token},
                success:function(data){
                    $('#itemList').fadeIn();
                    $('#itemList').html(data);
                }
            })
        }
    });
})
</script>
@endsection …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax laravel laravel-5.8

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

有没有办法保护laravel tinker?

我想知道是否可以扩展或替换该php artisan tinker命令,因此它首先要求进行身份验证,以作为看门人可以使用它的方式。

我尝试了以下方法:

<?php

namespace App\Console\Commands;

use Laravel\Tinker\Console\TinkerCommand;
use Illuminate\Support\Facades\Auth;

class Tinker extends TinkerCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'tinker';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return …
Run Code Online (Sandbox Code Playgroud)

laravel tinker laravel-artisan

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

播种器内的函数调用未定义的函数 Termwind\ValueObjects\mb_strimwidth()

我有一个项目,我有一个“习惯”表,该表需要一个播种器来为其提供数据,简单地说,它是一个带有原始数据的播种器,我需要烹饪它,换句话说,我需要处理就像这样...

\n
public function run()\n{\n    $Habits = [\n        \'Good\' => [\'A\', \'B\', \'C\', \'D\', \'E\', \'F\', \'G\', \'H\', \'I\', \'J\'],\n        \'Neutral\' => [\'k\', \'l\', \'m\', \'n\', \'o\', \'p\', \'q\', \'r\', \'t\'],\n        \'\xe2\x98\xb9\xef\xb8\x8fBad\' => [\'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\', \'9\', \'10\'],\n    ];\n        \n    foreach ($habits as $habit_category => $names) {\n        foreach ($names as $name) {\n            DB::table(\'habits\')->insert([\n                \'name\' => $name,\n                \'category\' => $habit_category\n            ]);\n        }\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这是数据库播种器

\n
public function run()\n{\n    $this->call([\n        HabitsSeeder::class,\n    ]);\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我知道逻辑没有缺陷,但我不知道我是否做得正确,但无论如何,给出的错误在标题中:

\n
\n …

laravel laravel-seeding laravel-9

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

Laravel 仅从分页获取数据

我查询用户列表如下:

$users = \App\User::selectRaw('id, "user_name"')->paginate(2);
Run Code Online (Sandbox Code Playgroud)

返回:

{
    current_page: 1,
    data: [
        {
            id: 2,
            user_name: "user_name"
        },
        {
            id: 3,
            user_name: "user_name"
        }
    ],
    first_page_url: "http://localhost:8000/users?page=1",
    from: 1,
    last_page: 2,
    last_page_url: "http://localhost:8000/users?page=2",
    next_page_url: "http://localhost:8000/users?page=2",
    path: "http://localhost:8000/users",
    per_page: 2,
    prev_page_url: null,
    to: 2,
    total: 3
}
Run Code Online (Sandbox Code Playgroud)

我需要将存储在其中的用户值存储data:到一个变量中,我该如何实现呢?

php pagination json laravel

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

Laravel:通过 axios 登录不需要 CSRF 令牌

当我使用表单发布到 /login 路由时,需要有效的 CSRF 令牌。

<form role="form" method="POST" action="/login">
Run Code Online (Sandbox Code Playgroud)

但是,我可以完全登录而无需令牌,只需使用:

axios.post("/login", { email:this.email, password:this.password })
    .then((res) => {
        window.location.href = "/dashboard";
    })
Run Code Online (Sandbox Code Playgroud)

这是一个安全风险,对吧?这是为什么?我该如何修复它?

forms authentication csrf laravel

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

为什么 elquent 的速度低于 db query builder?

我有两个像这样的流明查询

  1. Doc:all();

  2. DB:table('docs')->get();

第一个的速度是 946 毫秒,第二个的速度是 46 毫秒(在 Postman 中)

你能告诉我这件事吗?

php laravel lumen

-1
推荐指数
1
解决办法
64
查看次数