我正在尝试将backAfterSaveStatus值绑定到隐藏输入,由于某种原因,提交的表单backAfterSave值为空。之后我回去再次提交表单 -backAfterSave值是1。问题出在哪里?我没有尝试过同样的事情prevent,submit()但它仍然无法正常工作。此外,我已经转储了 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) 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 …
我正在尝试从视图生成 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) 我试图使用 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 …
在 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) 我正在尝试构建一个带有可搜索选项的城市选择选项表单。到目前为止,我已经构建了这个,但是所选的数据没有被保存,并且我的代码仍然缺乏搜索功能。
{!! 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) 我正在创建一个表,其行包含在 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>\nRun Code Online (Sandbox Code Playgroud)\n但在行组件中,每当我更改输入或从下拉选择中选择某些内容时,该组件都不会重新渲染。
\n我想知道为什么会发生这种情况。所以我打开控制台并看到:
\nLivewire: 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\nRun Code Online (Sandbox Code Playgroud)\n这是组件刀片文件
\nLivewire: Multiple root elements detected. This …Run Code Online (Sandbox Code Playgroud) 我一直在针对我的上下文尝试本教程(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) 我想知道是否可以扩展或替换该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) 我有一个项目,我有一个“习惯”表,该表需要一个播种器来为其提供数据,简单地说,它是一个带有原始数据的播种器,我需要烹饪它,换句话说,我需要处理就像这样...
\npublic 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}\nRun Code Online (Sandbox Code Playgroud)\n这是数据库播种器
\npublic function run()\n{\n $this->call([\n HabitsSeeder::class,\n ]);\n}\nRun Code Online (Sandbox Code Playgroud)\n我知道逻辑没有缺陷,但我不知道我是否做得正确,但无论如何,给出的错误在标题中:
\n\n …
我查询用户列表如下:
$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:到一个变量中,我该如何实现呢?
当我使用表单发布到 /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)
这是一个安全风险,对吧?这是为什么?我该如何修复它?
我有两个像这样的流明查询
Doc:all();
DB:table('docs')->get();
第一个的速度是 946 毫秒,第二个的速度是 46 毫秒(在 Postman 中)
你能告诉我这件事吗?
laravel ×11
php ×5
javascript ×3
forms ×2
http ×2
ajax ×1
alpine.js ×1
csrf ×1
dompdf ×1
fetch ×1
get ×1
html ×1
http-caching ×1
idempotent ×1
jquery ×1
json ×1
laravel-5 ×1
laravel-5.8 ×1
laravel-9 ×1
lumen ×1
mpdf ×1
pagination ×1
tailwind-css ×1
tcpdf ×1
tinker ×1