laravel-blade 相关问题

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

我在 Laravel 中使用 .blade.php 视图时遇到问题

这是我的路线 路线::get('/product/create',[ProductoController::class,'createProduct'])->name('product.create')->middleware('auth'); 路线::post('/product/create',[ProductoController::...

回答 1 投票 0

我有多个房型,每个房型有多行定价

我有多种房间类型,每种房间类型都有多行定价,但当我执行计算时,它会计算每种房间类型表格,但如果我为该房间类型添加新的 pax 平板行,那么它

回答 1 投票 0

患者卡未永久显示

我正在尝试创建一张患者卡,该卡会自动添加到“就座等待”区域,一开始它向我显示该卡,然后不到一秒钟它就消失了 我怎样才能

回答 2 投票 0

文本透明实用程序类不适用于 TailwindCSS

我正在尝试使用本指南将渐变应用于某些文本。一切都在进行中,直到尝试使文本透明以允许渐变通过。这就是我最终得到的结果: ...

回答 1 投票 0

Laravel 11 AJAX 请求只显示响应数据,不执行成功函数

Laravel 11 AJAX 请求仅显示响应数据,而不执行 AJAX 中的成功函数。我已经添加了下面的所有代码。 索引.blade.php: Laravel 11 AJAX 请求仅显示响应数据,而不执行 AJAX 中的成功函数。我已添加以下所有代码。 Index.blade.php: <table id="employeesTable" class="table table-hover datatable"> <thead> <tr> <th>ID</th> <th>Image</th> <th>Full Name</th> <th>Email</th> <th>Details</th> <th>Status</th> <th>Action</th> </tr> </thead> <tbody> </tbody> </table> 脚本: <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> <script> $(document).ready(function() { fetchEmployees(); function fetchEmployees() { $.ajax({ url: '/system/employee', type: 'GET', dataType: "json", success: function(res) { console.log(res.employees); } }); } }); </script> 在控制器中: public function index() { $query = Employee::query(); $employees = $query->orderBy('created_at', 'desc') ->get(); return response()->json(["employees" => $employees]); } 显示此内容的回复 --> 回复SS 我还没找到解决办法! 运行 config:cache Artisan 命令来缓存配置文件: php artisan config:cache 这将在 Laravel 应用程序的 bootstrap/cache 目录中生成一个缓存的配置文件 (config.php)。确保 Web 服务器可写入该目录。

回答 1 投票 0

如何在blade中包含一个带有句点(.)作为文件名一部分的blade文件

我有以下路径的部分视图。 /views/acp/review/check.details.blade.php 我如何使用刀片包含这样的文件,因为如果我这样做 @include('views.acp.review.check.details') 我明白了...

回答 2 投票 0

laravel - 访问覆盖的包刀片文件中的原始刀片文件

我正在创建一个动态 Laravel 包,可以在其中扩展刀片文件。我的想法是提供一个基本模板并使用相同的名称多次扩展它。让我们简化一下我的说法 文件:- 打包...

回答 1 投票 0

更改变量名称时显示未定义变量

在我的控制器页面中,我试图将所有数据从模式返回到视图。我将所有数据保存在一个变量中并传递到视图页面。当我将变量名称保留为 $post 时,我得到

回答 3 投票 0

注册账号成功后如何路由登录?

**我一直在尝试登录并注册我们制作的网站。我正在使用 vs code 和 laravel Blade 模板。 这是我的登录代码:** **我一直在尝试登录并注册我们制作的网站。我正在使用 vs code 和 laravel Blade 模板。 这是我的登录代码:** <?php session_start(); $validationRules = [ 'email' => ['required', 'email'], 'password' => ['required', 'regex:/^[A-Za-z0-9\s-_]+$/'] ]; $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { foreach ($validationRules as $field => $rules) { foreach ($rules as $rule) { switch ($rule) { case 'required': if (empty($_POST[$field])) { $errors[$field] = ucfirst($field) . ' is required.'; } break; case 'email': if (!filter_var($_POST[$field], FILTER_VALIDATE_EMAIL)) { $errors[$field] = 'Invalid email format.'; } break; case 'regex': if (!preg_match('/^[A-Za-z0-9\s-_]+$/', $_POST[$field])) { $errors[$field] = ucfirst($field) . ' contains invalid characters.'; } break; } } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="StyleLogin.css"> <title>Style Sync Login Page</title> </head> <body> <div class="card"> <div class="card-header"> <img src="{{ asset('logo.png') }}" alt="Style Sync Logo"> <div class="title-container"> <h1>Account Login</h1> </div> <div class="card-body"> <?php if (!empty($errors)): ?> <div class="alert alert-danger"> <ul> <?php foreach ($errors as $error): ?> <li><?= $error ?></li> <?php endforeach; ?> </ul> </div> <?php endif; ?> <form action="login" method="POST"> @csrf <div class="form-group"> <label for="email">Email</label> <input type="email" id="email" name="email" required> </div> <div class="form-group"> <label for="password">Password</label> <input type="password" id="password" name="password" required> </div> <button type="submit">Login</button> </form> <p>Don't have an account?<a href="{{ route('registration') }}">Register an Account</a></p> </div> </div> </body> </html> 然后这就是我在登录控制器上的内容: <?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; class LoginController extends Controller { public function showLoginForm() { return view('auth.login'); } public function login(Request $request) { $validator = Validator::make($request->all(), [ 'email' => 'required|email', 'password' => 'required', ]); if ($validator->fails()) { return redirect()->route('login')->withErrors($validator)->withInput(); } if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) { return redirect()->route('dashboard'); } else { return redirect()->route('login')->with('error', 'Invalid email or password'); } } } 这是注册码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Style Sync Registration Page</title> <link rel="stylesheet" href="StyleRegistration.css"> </head> <body> <div class="card"> <div class="card-header"> <img src="{{ asset('logo.png') }}" alt="Style Sync Logo"> <h1>Account Registration</h1> </div> <div class="card-body"> <form method="POST" action="{{ route('registration') }}"> @csrf <div> <label for="name">Name</label> <input id="name" type="text" name="name" value="{{ old('name') }}" required> @error('name') <div class="error">{{ $message }}</div> @enderror </div> <div> <label for="email">Email</label> <input id="email" type="email" name="email" value="{{ old('email') }}" required> @error('email') <div class="error">{{ $message }}</div> @enderror </div> <div> <label for="password">Password</label> <input id="password" type="password" name="password" required> @error('password') <div class="error">{{ $message }}</div> @enderror </div> <div> <label for="password_confirmation">Confirm Password</label> <input id="password_confirmation" type="password" name="password_confirmation" required> </div> <button type="submit">Register</button> </form> <p>Already have an account? <a href="{{ route('login') }}">Login here!</a></p> </div> </div> </body> </html> 那么这就是注册控制器 <?php namespace App\Http\Controllers\Auth; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Validator; use App\Models\User; class RegistrationController extends Controller { public function showRegistrationForm() { return view('auth.registration'); } public function register(Request $request) { $validator = Validator::make($request->all(), [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:8|confirmed', ]); if ($validator->fails()) { return redirect()->route('registration')->withErrors($validator)->withInput(); } User::create([ 'name' => $request->name, 'email' => $request->email, 'password' => bcrypt($request->password), ]); return redirect()->route('login')->with('success', 'Registration successful! Please login.'); } } 这是web.php路由 <?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Auth\RegistrationController; use App\Http\Controllers\DashboardController; Route::get('/', function () { return view('welcome'); }); Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login'); Route::post('/login', [LoginController::class, 'login']); Route::get('/registration', [RegistrationController::class, 'showRegistrationForm'])->name('registration'); Route::post('/registration', [RegistrationController::class, 'registration']); Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard'); 我尝试了不同的路由,但仍然不起作用 这是弹出的错误: 调用未定义方法 App\Http\Controllers\Auth\RegistrationController::registration() 错误“Call to undefined method App\Http\Controllers\Auth\RegistrationController::registration()”表示Laravel无法在RegistrationController中找到名为registration()的方法。 查看你的RegistrationController,负责处理注册过程的方法名为register(),而不是registration()。因此,当您尝试在路由文件中调用 Registration() 时,Laravel 会抛出错误,因为该方法不存在。 要解决此问题,您需要更新路由文件 (web.php) 以在注册路由中使用正确的方法名称 (register()): Route::post('/registration', [RegistrationController::class, 'register']);

回答 1 投票 0

在对 Laravel 查询结果集进行排序时指定一些要优先考虑的“粘性”值

我目前有一个显示所有国家/地区的国家/地区下拉菜单。通常我的用户会在“美国”、“英国”或“加拿大”之间进行选择。我不想要我的...

回答 3 投票 0

如何移动下拉菜单顶部的 3 个热门国家/地区

我目前有一个显示所有国家/地区的国家/地区下拉菜单。通常我的用户会在“美国”、“英国”或“加拿大”之间进行选择。我不想要我的...

回答 3 投票 0

为什么 Alpine x-data 对其自身的属性变化没有反应?

有一个输入组件。代码如下。 @道具([ '禁用' => false, '隐藏' => 假, '类型' => '文本', '状态' => 空, '边框类' => '' ]) @php 开关($状态){ 案例 'a...

回答 1 投票 0

Laravel 图像上传文件路径但未显示在视图中

我目前正在 Laravel 10 中开发一个电子商务项目。在类别部分的管理仪表板中,我设置了两列,一列用于类别图像,另一列用于类别横幅

回答 1 投票 0

Laravel 多段路由导致找不到资源

如果我的路线上有多个路段,它会弄乱我的资产路径 当我访问 url('/blogadmin') 时,我的资源位于 href="admin/css/simplebar.css" 上 但是当我访问 url('/blogs/...

回答 1 投票 0

SQLSTATE[HY000]:一般错误:1366 不正确的整数值:第 1 行的列“category_id”的“[“2”]”

我无法从前端保存或更新数据,出现此错误。我有一个类别表、一个项目表和一个类别项目(数据透视)表。 以下是我的项目控制器文件...

回答 1 投票 0

Laravel Blade 条件部分

如果条件为真,我想在视图中显示一个部分,如果条件为假,则显示另一部分。我使用 PhpStorm 作为 IDE,在这些情况下我得到的是指令未关闭: @if(条件...

回答 2 投票 0

如何使用动态密钥在 laravel livewire 表单中获取错误?

我想在 foreach 中使用带有动态键的 livewire 形式获取错误消息,如下所示 我想使用 foreach 内部的 livewire 表单以及像这样的动态键来获取错误消息 <x-input-error class="mt-2" :messages="$errors->get('form.productData.product_variants.{{ $index }}.name')" /> 但是如果我设置的form.productData.product_variants.0.name规则有任何错误,该消息不会显示。 当我使用这样的静态密钥访问错误消息时 <x-input-error class="mt-2" :messages="$errors->get('form.productData.product_variants.0.name')" /> 显示错误消息。 如何在我的 foreach 循环中使用 $index 中的动态键来获取错误消息? 在 Laravel Livewire 中,您可以使用 Livewire 的 $errors 属性和 getErrorBag() 方法动态设置表单字段的错误键。以下是实现这一目标的方法: 为错误设置动态密钥: <div> <input type="text" wire:model="username"> @error($dynamicErrorKey) <span class="error">{{ $message }}</span> @enderror </div> 在此示例中,$dynamicErrorKey 表示动态错误键,您可以根据 Livewire 组件中的某些条件设置该键。 设置动态错误消息: public function updatedUsername() { if ($this->username === 'admin') { $this->addError($this->dynamicErrorKey, 'Username cannot be "admin"'); } } 在updatedUsername方法中,您可以根据一定的条件动态设置指定错误键的错误消息。 初始化动态错误键:确保 $dynamicErrorKey 在您的 Livewire 组件中初始化。 public $dynamicErrorKey = 'default_error_key'; 您可以根据您的应用程序逻辑动态更新 $dynamicErrorKey 的值。 通过执行以下步骤,您可以根据您的具体要求动态设置 Livewire 组件中表单字段的错误键和消息。这允许在处理表单验证错误时实现灵活性和自定义。

回答 1 投票 0

Laravel - 如果 json 值保存在数据库中,请选中复选框

我有以json格式保存的数据库记录。在编辑表单中,如果值保存在数据库中,我希望选中这些复选框。 数据库价值 |身份证 |项目 | |----|------...

回答 3 投票 0

如果产品在显示它的图像表中有多个图像,并且如果不存在

如果产品在显示它的图像表中有多个图像,并且如果不存在,则显示为空,我该如何做条件 @foreach($产品作为$产品) {{ $

回答 1 投票 0

如何使用 Laravel Excel 在单个工作表中添加多个表格

我一直在尝试使用 FromViews 将多个表包含在一张表中,但它总是以失败告终。 这就是我的代码的样子 ... 我一直在尝试使用 FromViews 将多个表包含在一张表中,但它总是以失败告终。 这就是我的代码的样子 <table> <tr> <td> <table> ... </table> </td> </tr> <tr> <td> <table> ... </table> </td> </tr> </table> 我想要实现的目标: 以及如何在blade中使用边框而不是使用withEvents?谢谢你。 我一直在尝试使用 FromViews 将多个表包含在一张表中,但它总是以失败告终。 根据我的经验,你不能这样做。您要么必须弄清楚如何获取需要的数据,要么使用 PHPSpreadsheet 的 setCellValue 方法。 如何在blade中使用边框而不是使用withEvents? PHPSpreadsheet 理解一些内联样式。边境就是其中之一。您只需使用<td style="border: 1px solid black">...</td>即可。 想要更复杂的款式?您不得不使用底层 PHPSpreadsheet 的样式方法。

回答 1 投票 0

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