laravel-blade 相关问题

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

Laravel 中使用 Bootstrap Toasts 代替 Bootstrap 警报

我目前正在使用 Bootstrap Alert 在 laravel 应用程序中显示消息 @if(会话::has('消息')) 我目前正在使用 Bootstrap Alert 在 laravel 应用程序中显示消息 @if(Session::has('message')) <div class="alert alert-{{ session('class') }} alert-dismissible fade show rounded-0" role="alert"> <i class="fa fa-{{ session('icon') }}"></i> {{ session('message') }} <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div> @endif 但我想使用带有动态消息的 Bootstrap toast <div class="toast-container position-fixed bottom-0 end-0 p-3"> <div id="toast" class="toast align-items-center text-bg-info text-white rounded-0" role="alert" aria-live="assertive" aria-atomic="true"> <div class="d-flex"> <div class="toast-body"> Some Message <i class="far fa-face-smile"></i> </div> <button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button> </div> </div> </div> 我已经创建了警报组件。我应该如何触发toast系统。 使用 laravel 10 和 bootstrap 5.3 @if(Session::has('message')) <div class="toast-container position-fixed bottom-0 end-0 p-3"> <div id="toast" class="toast align-items-center text-bg-info text-white rounded-0" role="toast" aria-live="assertive" aria-atomic="true"> <div class="d-flex"> <div class="toast-body"> {{session('message')}} <i class="far fa-face-smile"></i> </div> <button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button> </div> </div> </div> @endif 这会对你有帮助 当你传递 flash 消息时,总是尝试使用 session() 和会话的密钥,例如消息或错误。 将其添加到您的基本布局或视图中: <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script> 为您的 Toast 消息创建新的刀片视图 - toast.blade.php。 <div class="toast align-items-center text-bg-info text-white rounded-0" role="alert" aria-live="assertive" aria-atomic="true"> <div class="d-flex"> <div class="toast-body"> {{ $message }} </div> <button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button> </div> </div> 使用 with() 传递 toast 消息。 return view('your-view')->with('message', 'This is a toast message.'); 将此添加到您想要显示 toast 消息的位置: @if(session('message')) @include('toast') @endif 要显示toast,可以使用JS。 Bootstrap 5.3 toast 需要触发 JavaScript。 <script> $(document).ready(function() { // Get the toast element by its ID var toastElement = document.getElementById('toast'); // Create a new Bootstrap Toast instance var toast = new bootstrap.Toast(toastElement); // Show the toast toast.show(); }); </script>

回答 2 投票 0

Laravel Livewire:Bootstrap Select-Picker 无法渲染

我想根据第 4 步的多步骤表单中选定的所有类别加载类别和多个子类别,但我无法使用

回答 1 投票 0

{{ }} 和 {!! 有什么区别? !!} 在 Laravel Blade 文件中?

在laravel框架中我们可以使用blade在html文件中添加PHP代码。 我们同时使用 {{ }} 和 {!! Laravel 的 Blade 文件中的 !!} 语法。 他们有什么区别?

回答 6 投票 0

我们可以在 Laravel 中的 destroy() 中使用条件重定向到另一个路由吗?

场景:某个帖子在所有帖子列表视图和 postShow 视图中都有一个删除按钮。因此,如果该帖子从列表中删除,它将返回 back()->with('success', 'Some message') 但如果我们删除...

回答 3 投票 0

如何在 Laravel 组件中传递数组变量?

我想将数组变量传递给我的组件。 这是我的代码: @php $面包屑 = [ [ '姓名' => '学员', 'link' => 路线('trainee.list') ] ]; @endphp @节('

回答 1 投票 0

ReferenceError <component>未定义,但在 Laravel 10 和 Livewire 3.0 中运行两次

在使用 Laravel 10.20 和 Livewire 3.0.0-beta.10 运行时,我发现 Alpine JS 组件出现奇怪的行为。我有一个 Laravel Blade 组件,其中包含一个 Alpine JS 组件。 <...

回答 1 投票 0

如何使用 Laravel 将 Blade 文件包含到另一个 Blade 文件模式弹出窗口中

我开发了一个产品详细信息刀片文件,我想在产品详细信息页面模式弹出窗口中包含另一个刀片文件,并且该刀片文件没有不同的布局。我包括...

回答 2 投票 0

laravel [Vue warn]:编译模板时出错:

我没有在我的应用程序中使用任何 vue 组件,我只是使用 app.js 文件来将我的 npm 包编译到我的资产 js/app.js 或 css/app.css 但我收到 [Vue warn ]: 编译模板时出错:错误...

回答 2 投票 0

VSCode 语言标识符不适用于 Laravel Blade

VS Code 不会自动定义 .blade.php 文件。也就是说,我应该通过右下角的“选择语言模式”按钮或者通过热键来手动切换模式...

回答 3 投票 0

@vite( 'resources/css/app.css' 'resources/js/app.js' ) 不适用于 laravel 9、vite 4.0.0

在 Laravel 9 应用程序中,我使用以下命令安装了 Laravel auth(使用 Jetstreem livewire 和 vite-4.0.0): 作曲家需要 laravel/jetstream php artisan jetstream:安装 livewire PHP 艺术...

回答 2 投票 0

我如何使用php格式化文件大小?

我有一个表单,在成功上传文件后上传文件,我想显示每个文件的大小,KB、MB、GB 取决于文件大小。 像这样 我有一个表单,在成功上传文件后我要上传文件,我想显示每个文件的大小,KB、MB、GB 取决于文件大小。 像这样 <div class="d-flex align-items-center gap-3"> <img src="{{asset('images/icons/file-icon.svg')}}" alt="" style="width: 70px;height: 70px;border-radius: 10px;"> <div> <p class="font-weight-bold m-0 text-primary-dark">{{ $media->name }}</p> <p class="m-0 font-weight-bold text-primary-dark">{{ formatFileSize($media->size) }}</p> </div> </div> 我创建了一个功能,在我的刀片中发送这样的尺寸 {{ formatFileSize($media->size) }} 这应该给我一个正确的单位格式 您可以通过使用像这样的辅助函数来实现这一点 function formatFileSize($size): string { $units = ['B', 'KB', 'MB', 'GB', 'TB']; $base = 1024; $unitIndex = 0; while ($size >= $base && $unitIndex < count($units) - 1) { $size /= $base; $unitIndex++; } return round($size, 2) . ' ' . $units[$unitIndex]; }

回答 1 投票 0

如何在 Laravel 6 中使用 Validator 验证 2 个分隔的字符串?

我想使用 Laravel 6 对输入字符串进行验证,输入条件如下。 userNo = "5031234567" => Len = 10 位数字且必须以 503 开头。 我尝试过...

回答 1 投票 0

Laravel 文件夹结构中 JSON 文件的存储位置

我想将一些数据存储在 JSON 文件中。数据将使用 json_decode 函数进行解码并传递给视图。 文件示例: { “房间”:[ { “名称”:“奥拉·麦格纳 1”, “camera_u...

回答 1 投票 0

解析 JSON 数据并使用循环在表格中显示

我正在使用 Laravel 开发一个网站,其中我有来自服务器的 JSON 响应,如下所示: [{“id”:1,“user_id”:“1”,“患者姓名”:“kk”,“年龄”...

回答 1 投票 0

Laravel 10.x 本地化无法使用会话工作

我在互联网上尝试了几个教程,但它不起作用或语言没有改变,我已经将翻译存储到 \lang 目录中,并且会话已经设置为本地化 S...

回答 1 投票 0

制作一个包含blade语法的函数

我看到了这把刀片。现在,我认为其中有 6 个块,因为我不知道如何重构它。 我有这把刀片。现在,我认为有 6 个块,因为我不知道如何重构它。 <div class="row filemanager"> <div class="col-sm-12"> @foreach ($devices as $device) @if( $device->vlan_id == 100 AND $device->device_activity == 'ACTIVE' ) <div class="col-xs-6 col-sm-4 col-md-2 text-center"> <div class="thmb"> <div class="btn-group fm-group" style="display: none;"> <button type="button" class="btn btn-default dropdown-toggle fm-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu fm-menu" role="menu"> <li id="device-menu"> <a class="changeDeviceNameBtn" href="#"><i class="fa fa-pencil"></i> Change Device Name </a> </li> </ul> </div> <div class="thmb-prev"> <a href="/{{$cpe_mac}}/device/{{$device->device_mac}}"> @if(isset($device->device_name)) {{-- Show base on device name --}} <img src="/images/photos/devices/{{img($device->device_name)}}.jpg" class="draggable img-responsive" alt=""> @else {{-- No Device Name Set --}} @if($device->hostname != '') {{-- Show base on hostname --}} <img src="/images/photos/devices/{{img($device->hostname)}}.jpg" class="draggable img-responsive" alt=""> @else {{-- Show default --}} <img src="/images/photos/devices/no-img.jpg" class="draggable img-responsive" alt=""> @endif @endif </a> </div> <h5 class="fm-title device_name"> <a href="/{{$cpe_mac}}/device/{{$device->device_mac}}"> @if($device->hostname == '') No Devicename @else {{ $device->hostname}} @endif </a> </h5> <h5 class="text-muted device_ip">{{$device->ip_address}}</h5> <h5 class="text-muted device_mac">{{$device->device_mac}}</h5> <?php $status = ucfirst(strtolower($device->device_activity)); if ($status == 'Active'){ $color = '#1CAF9A'; }else{ $color = '#D9534F'; } ?> <h5>{{ $status }} <i class="fa fa-circle" style="color:{{$color}}; margin-left: 7px;"></i> </h5> </div> </div> @endif @endforeach </div> </div> 我想制作一个包含该刀片的函数,并且只替换我的 $device->vlan_id,还有我的$device->device_activity。 例如, public static deviceRow(100,ACTIVE){ ... my blade ... } 现在,我只是将该函数执行 6 次,而不是将该代码块重复 6 次。 这可能吗? 您可以使用刀片制作部分并发送变量作为参数: 在您的父视图中执行以下操作: @foreach($somelist as $item) @include('view.partial', ['name' => $item->name]) @endforeach 在名为partial.blade.php的文件中,执行如下操作: {{ $device->$name }} 这是主要思想。告诉我是否有帮助... 您可以创建一个新视图并发送一些参数,同时包括: @include('my.view', ['device' => $myDevice, 'activity' => 'ACTIVE']) 数组的键将在您的视图中作为变量使用。 变量 $myDevice 在视图中可用作 $device my.view

回答 2 投票 0

spatie/laravel-html 是废弃的 laravelcollective/html 的良好替代品吗?

laravelcollective/html 已被放弃。我正在寻找可靠的替代品。许多人说 spatie/laravel-html 是不错的选择。但我面临着缺乏文档的问题。 示例来自

回答 1 投票 0

如何在 Laravel 中显示警告和弃用消息

如果我编写一些带有弃用通知的 PHP 代码,它会显示在本地环境中。 示例:index.php 如果我编写一些带有弃用通知的 PHP 代码,它会显示在本地环境中。 示例:index.php <?php function super(string $test='', string $essai) { return 'toto'; } super('sy', 1); exit; 显示: Deprecated: Optional parameter $test declared before required parameter $essai is implicitly treated as a required parameter in /var/www/public/index.php on line 9 这很好。 但是 Laravel 控制器中的完全相同的代码不会显示,并且不会存储在任何日志文件中。 我将配置 app.env 设置为“local”,将 app.debug 设置为 true,将 app.log_level 设置为“debug”。 知道我错过了什么吗? 根据文档: 记录弃用警告 PHP、Laravel 和其他库经常通知其用户某些 它们的功能已被弃用,并将在将来被删除 版本。如果您想记录这些弃用警告,您可以 在您的中指定您首选的 deprecations 日志通道 应用程序的 config/logging.php 配置文件: 'deprecations' => env('LOG_DEPRECATIONS_CHANNEL', 'null'), 'channels' => [ ... ] 或者,您可以定义一个名为 deprecations 的日志通道。如果一个日志通道 如果存在此名称,它将始终用于记录弃用: 'channels' => [ 'deprecations' => [ 'driver' => 'single', 'path' => storage_path('logs/php-deprecation-warnings.log'), ], ],

回答 1 投票 0

Laravel、Blade 和 React js 添加元标记以在服务器端 SEO 上渲染

我正在尝试在服务器端渲染元标记。所以我可以在共享链接上看到这个输出,如下所示: 我尝试了 React-Helmet,但它仅在加载时渲染。 我的控制器 公共函数 home()...

回答 1 投票 0

如何清除Livewire中的“文件多个”

我有一个刀片文件,其中包含以下 livewire(版本 2)代码: <input wire:model="commentFiles" type="file&...</desc> <question vote="0"> <p>我有一个刀片文件,其中包含以下 livewire(版本 2)代码:</p> <pre><code><textarea wire:model="enterComment"</textarea> <input wire:model="commentFiles" type="file" multiple> </code></pre> <p>上传工作就像魅力一样,但尝试在发出后清除文件不起作用 - 这是我的代码中的一些片段:</p> <pre><code>use WithFileUploads; public $commentFiles = []; </code></pre> <p>和上传:</p> <pre><code>foreach ($this->commentFiles as $uploadFile) { $stored = $uploadFile->store('case'); } </code></pre> <p>到目前为止我尝试清除“commentFiles”输入(全部不起作用):</p> <pre><code>$this->commentFiles = []; $this->commentFiles = null; foreach($this->commentFiles AS $file) { $file = null; } </code></pre> <p>之后(有效):</p> <pre><code>$this->enterComment = ''; $this->emit('reloadComments'); </code></pre> <p>大家有什么想法吗?</p> </question> <answer tick="false" vote="0"> <p>为文件上传元素的 id 创建公共属性。</p> <pre><code>public $id = 1; public function upload() { ... $this->id++; } </code></pre> <p>然后将 id 添加到您的上传元素。</p> <pre><code><input id="uploadFile{{ $id }}" wire:model="commentFiles" type="file" multiple> </code></pre> <p>这样,当上传完成时,$id 会递增,这会导致文件上传元素随着 id 的更改而重置。</p> </answer> </body></html>

回答 0 投票 0

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