laravel-blade 相关问题

Blade是Laravel提供的简单而强大的模板引擎。与其他流行的PHP模板引擎不同,Blade不会限制您在视图中使用纯PHP代码。

价格未显示正确的值/小数点

当您输入订购的最小金额时,我的 order.blade.php 出现问题,该值显示为零。正如您在下图中看到的,最小订购量为 100,价格为...

回答 1 投票 0

如何使用 Livewire (Laravel) 上传 pdf 文件?

这是我当前的代码: 这是我当前的电线:型号为 spk: 这是我当前的代码: 这是我当前的电线:型号为 spk: <?php namespace App\Http\Livewire\Spk; use App\Models\Spk; use Illuminate\Support\Facades\Storage; use Livewire\Component; use Livewire\WithFileUploads; class Form extends Component { use WithFileUploads; public $spk; public $submitButtonName; protected $rules = [ 'spk.file_path' => 'required|mimes:pdf,xlsx,xls,csv,txt,png,gif,jpg,jpeg|max:8192', ]; public function mount() { // Check if the spk property is set if (!$this->spk){ $this->spk = new Spk(); $this->submitButtonName = 'Create'; } else { $this->submitButtonName = 'Edit'; } } public function save() { $this->validate(); // Handle file upload if ($this->spk->file_path) { // Generate a unique filename with microtime $filename = 'spk' . microtime(true) . '.' . $this->spk->file_path->getClientOriginalExtension(); // Save the file to the storage directory $this->spk->file_path->storeAs('spk', $filename, 'public'); // Update the file_path attribute with the new filename $this->spk->file_path = $filename; } $this->spk->save(); session()->flash('message', 'SPK Saved!'); return redirect()->route('spks.index'); } public function render() { return view('livewire.spk.form'); } } 这是我当前的钢丝刀片视图: <form wire:submit.prevent="save" method="POST" enctype="multipart/form-data"> @csrf <div class="row"> <div class="px-4 py-2"> <x-label for="file_path" value="{{ __('File Path') }}" /> <x-input wire:model="spk.file_path" type="file" name="file_path" :value="old('file_path')" class="w-full" required autofocus /> @error('spk.file_path') <div>{{ $message }}</div> @enderror </div> <div class="px-4 pt-8 pb-4"> <button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-md w-full"> {{ __($submitButtonName) }} </button> </div> </div> </form> 我已经这样做了php artisan storage:link 我很困惑我的代码出了什么问题。 file_path 无法保存在数据库中。 我尝试做dd($this->spk->file_path);,这是结果。它显示“磁盘”=>“本地” 请帮我解决使用 livewire 上传文件的问题。谢谢! 我做了一些小的修改,现在它在类自己的属性上上传文件,而不是使用模型绑定到模型的属性。绑定到模型属性可能会对水合/重新水合属性产生问题 - 一般来说,不使用模型绑定被认为是更好的做法(在 Livewire v3 中,默认情况下禁用它)。 另一个值得注意的更改是将 required 规则替换为 nulllable - 这可能会或不正确更改(您需要自己确定),但由于您对 if ($this->spk->file_path) { 进行了明确检查,我认为它可以在不更改文件的情况下提交表格。 <?php namespace App\Http\Livewire\Spk; use App\Models\Spk; use Illuminate\Support\Facades\Storage; use Livewire\Component; use Livewire\WithFileUploads; class Form extends Component { use WithFileUploads; public $spk; public $spkFile; public $submitButtonName; protected $rules = [ 'spkFile' => 'nullable|mimes:pdf,xlsx,xls,csv,txt,png,gif,jpg,jpeg|max:8192', ]; public function mount() { // Check if the spk property is set if (!$this->spk){ $this->spk = new Spk(); $this->submitButtonName = 'Create'; } else { $this->submitButtonName = 'Edit'; } } public function save() { $this->validate(); // Handle file upload if ($this->spkFile) { // Generate a unique filename with microtime $filename = 'spk' . microtime(true) . '.' . $this->spkFile->getClientOriginalExtension(); // Save the file to the storage directory $this->spkFile->storeAs('spk', $filename, 'public'); // Update the file_path attribute with the new filename $this->spk->file_path = $filename; $this->spkFile = null; } $this->spk->save(); session()->flash('message', 'SPK Saved!'); return redirect()->route('spks.index'); } public function render() { return view('livewire.spk.form'); } } <form wire:submit.prevent="save" method="POST" enctype="multipart/form-data"> @csrf <div class="row"> <div class="px-4 py-2"> <x-label for="file_path" value="{{ __('File Path') }}" /> <x-input wire:model="spkFile" type="file" name="file_path" :value="old('file_path')" class="w-full" required autofocus /> @error('spkFile') <div>{{ $message }}</div> @enderror </div> <div class="px-4 pt-8 pb-4"> <button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-md w-full"> {{ __($submitButtonName) }} </button> </div> </div> </form>

回答 1 投票 0

Swal 未定义

我想在 Laravel 刀片视图中使用 Sweetalert 2。我收到这个错误。 话说我已经通过npm安装了它,但我没有做任何其他事情,我看到必须从...

回答 2 投票 0

未定义的变量:Laravel 8 上的 __env

这是我的代码: @foreach($comments->where("id_answered_comment", null) as $comment) @php

回答 1 投票 0

如何在同一查询上区分按年份和按类别分组?

我想在distinct和groupby之后查询结果 这是我的代码 $结果 = DB::table('dokumen') ->join('pengadaan', 'dokumen.id_jenis_pengadaan', '=', 'pengadaan.id') ...

回答 2 投票 0

如何在 Laravel Blade 视图中返回错误/成功消息?

发送请求的URL是: http://localhost:8000/my_details?my_id='.$id 我的控制器看起来像这样: 公共函数my_action(请求$请求){ $myauth=$请求->验证([ ...

回答 2 投票 0

未显示产品描述 Laravel

我就遇到这样的问题。我的网站上的一些产品已经存在于数据库中,并且一切正常 但是在创建一本新书时,我想向我添加属性...

回答 1 投票 0

如何验证输入并在同一网址内使用自定义消息进行重定向?

我有一个通过带有可变参数的 URL 访问的 Blade 文件。我想通过输入验证检查输入是否为空,并返回到相同的 URL 并显示成功/错误消息。 我的BL...

回答 1 投票 0

路线供应商/产品/操作/新不支持 PUT 方法。支持的方法:POST

对.... 疯狂的是,整个代码看起来都是正确的,但仍然出现此错误。 但一定是某个地方出了问题。 产品控制器 公共函数新(请求$请求){ $请求-...

回答 1 投票 0

{{dump('string')}} 输出值两次

使用 Laravel 5.5.34,我在使用 dump() 帮助程序在 Blade 模板中输出调试信息时遇到问题。 {{ 转储('测试') }} 产生以下输出: 我没想到原始字符串......

回答 2 投票 0

在 Blade 中显示 Laravel 的 dd() 结果,无需 die -> d(), dump()

我想以与 dd() 函数相同的样式显示会话的内容。 我尝试这样做: {!!转储(会话()->全部())!!} 我收到此错误: ...

回答 1 投票 0

Laravel:嵌套循环 html 选项并增加缩进(前缀)

我想在html选项标签中显示缩进的子类别。我在一个单独的文件中创建了一个递归迭代,并在 foreach 语句中导入该文件。 通过第一个子类别,我得到了一个前缀...

回答 1 投票 0

如何在 Laravel 8 中每次在同一个 cookie 中插入多个值

我的控制器 公共函数addcart(请求$请求) { $data1 = 数组($request); if (is_array($data1) || is_object($data1)) { foreach ($data1 作为 $data1) { // 如果 (!...

回答 2 投票 0

我无法运行我的 Laravel 应用程序

下午好。我在本地运行 Laravel 应用程序时遇到一些问题。我对 Laravel 或 PHP Artisan 不太了解,我需要一些帮助。我对

回答 1 投票 0

使用分页 [Livewire3] 后 Flowbite 模式无法工作

我正在学习如何使用 Livewire。表格第一页上的所有模式都工作正常。但是使用分页后,模式就不再起作用了。我添加了 console.log 来检查我是否嗨...

回答 1 投票 0

将角色类型传递给 Laratrust 表单数据库变量

我正在使用 Laratrust 和 laravel 根据角色显示数据库中的记录。每条记录都有一个角色类型字段(下表示例)。 在我的刀片视图中,我想将它们显示为...

回答 1 投票 0

如何使用从 Laravel 数据库中获取的数据检查复选框

我在检索数据并使用它来检查 Laravel 中的复选框时遇到问题。我希望当打开编辑页面时,将根据数据库中的记录选中复选框。 编辑

回答 1 投票 0

Laravel 表单验证在表单错误时重定向回主页,而不是停留在同一页面上

我有一个联系表格,提交后已成功发送到数据库。问题是当我在网页上检查验证时。使用 Laravel $error 验证可以正确显示错误。该项目...

回答 2 投票 0

home.blade.php 左侧表单登录

家庭刀片中的登录表单仍然固定在左侧,我需要将其放在页面中央,你能帮助我吗?整个完整视图位于存储库中 我尝试过 g...

回答 1 投票 0

我在foreach中有模式对话框,想在提交按钮后显示div动画

我将其放在表格单元格中并将 #key 传递到模式对话框 我将其放在表格单元格中并将 #key 传递到模式对话框 <td> <a id="myButton" href="#!" data-toggle="modal" data-target="#restoreBackup_{{ $key }}" class="btn btn-warning">Restore Backups</a> </td> 当我单击“恢复”按钮时,会出现在 foreach 中打开一个表单的模式对话框 我的模式: @foreach ($backups as $key => $backup) {{-- //restore section--}} <div class="modal fade" id="restoreBackup_{{ $key }}" tabindex="-1" role="dialog" aria-labelledby="restoreBackup_{{ $key }}" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered modal-lg" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">{{ translate('Confirm Restore') }}</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="alert alert-warning" role="alert"> <b>Do you really want to restore this backup? {{ $key }}</b> </div> <form id="frm_restore_{{ $key }}" action="{{ route('backups.restore') }}" method="POST"> @csrf <input type="hidden" name="key" value="{{ $key }}" /> <input type="hidden" name="backuptype" value="{{ $backup['type'] }}" /> <div class="modal-body"> @if ($backup['type'] == 0) <div class="form-group"> <h5 class="modal-title">Choose Your Restore Type</h5> </div> <div class="radio-button"> <input type="radio" id="radio30" name="restoretype" value="0" checked> <label for="radio30">DataBase And Folder</label> <input type="radio" id="radio31" name="restoretype" value="1"> <label for="radio31">Only DataBase</label> <input type="radio" id="radio32" name="restoretype" value="2"> <label for="radio32">Only Folder</label> </div> @endif <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> <button type="submit" class="btn btn-warning">Restore</button> </div> </div> </form> <div id="animationdiv_{{ $key }}"></div> </div> </div> </div> @endforeach 如你所见,我有一个像这样的div: <div id="animationdiv_{{ $key }}"></div> 我有一个定义动画的CSS代码: .currently-loading { opacity: 0.75; -moz-opacity: 0.75; filter: alpha(opacity=75); background-image: url({{ static_asset('backup_restore_loading.gif') }}); background-repeat: no-repeat; position: absolute; height: 100%; width: 100%; z-index: 10; background-size: contain; } 如果我在 foreach 循环之外打开一个对话框模式,例如它的表单名称是 frm_backup,那么如果我使用以下代码提交它,我可以在 JavaScript 部分中显示动画: var frm_backup = document.getElementById('frm_backup'); frm_backup.addEventListener('submit', bmdLoading1); //display loading message function bmdLoading1() { var divloading1 = ''; divloading1 = '<div class="currently-loading"></div>' $("#animation").html(divloading1); } 但是如果我在 foreach 循环中打开一个对话框模式,我不知道如何传递 $key 并使用 $key 显示 div 动画 在这种情况下,每个模态都有一个类似 id="frm_restore_{{ $key }}" 的名称,每个 div 都有一个类似 id="animationdiv_{{ $key }}" 的名称 这取决于您要向哪个元素添加动画“div”。但你必须编辑他的html。您正在使用要显示的 div 创建一个变量,但没有将其分配给代码中的任何位置。类似的东西 $('#modal-body').html(divloading1);

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.