laravel 相关问题

Laravel是一个免费的开源PHP Web框架,由Taylor Otwell创建,用于遵循模型 - 视图 - 控制器(MVC)架构模式并基于Symfony开发Web应用程序。 Laravel的源代码托管在GitHub上,并根据MIT许可条款获得许可。

laravel eloquent ->whereHas - 编写你自己的存在(子查询)

Laravel Eloquent ->whereHas() 使用 anexists() 子查询 - https://dev.mysql.com/doc/refman/8.0/en/exists-and-not-exists-subqueries.html - 为了返回你的结果。 我想写我...

回答 3 投票 0

Laravel 雄辩,如何在关系表中用 OrWhere 进行查询

我有一个游戏模型,与位置模型有关系。 我想在游戏的名称字段以及游戏位置的名称字段中进行搜索。而且比赛的开始时间必须大于今天的时间...

回答 1 投票 0

如何设置laravel sail以在docker compose上使用sqlite

首先,很容易设置laravel来使用sail 作曲家需要 laravel/sail --dev php artisan sail:安装 问题是,docker compose默认设置为使用mysql,但我实际上需要一个

回答 1 投票 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

使用过期日期登录

我的用户模型中有一个过期日期,我想在登录时检查。我在凭据方法中写了关于活动用户的信息,如下所示: 受保护的函数凭据(请求$请求){ 返回

回答 1 投票 0

如何在laravel中将2个表数据放入单变量数组中?

我有2个表用户和子管理员认为用户有3列而子管理员有2列我想将3+2(5列)数据放入单个可验证数组中 我想使用的技术是在用户...

回答 5 投票 0

将 Laravel 10 更新到版本 11

我尝试在将 Laravel 从版本 10 更新到 11 后运行我的应用程序。我在composer.json 中进行了一些更改,并将整个项目更新到 Laravel 11。但是,当我尝试执行索引时,我发现。 ..

回答 1 投票 0

如何在 Filament 中使用 ChartJs 创建堆叠条形图?

美好的一天,我需要您的帮助/指导来使用 Laravel Filament 中的 Chartjs 创建堆叠条形图。我有一个名为“任务”的表,它与“客户”表有关系。 e 的字段...

回答 1 投票 0

所有 Laravel 路线均已公开。如何将其移动到 app.js 或缩小(如果可能)

我在 Laravel、Vue.js 和 Inertia js 项目中使用 Ziggy。在查看页面源代码中,我可以清楚地看到所有 Laravel 路由。 常量 Ziggy...</desc> <question vote="9"> <p>我在 Laravel、Vue.js 和 Inertia js 项目中使用 Ziggy。在查看页面源码中,我可以清楚地看到所有的 Laravel 路由。</p> <pre><code>&lt;script type=&#34;text/javascript&#34;&gt; const Ziggy = {&#34;url&#34;:&#34;http:\/\/127.0.0.1:8787&#34;,&#34;port&#34;:8787,&#34;defaults&#34;:{},&#34;routes&#34;: ...... &#34;sup_finish_tt_order&#34;:{&#34;uri&#34;:&#34;front\/finishorder&#34;,&#34;methods&#34;:[&#34;POST&#34;]},&#34;assign__tt&#34;:{&#34;uri&#34;:&#34;front\/assigntt&#34;,&#34;methods&#34;:[&#34;POST&#34;]},&#34;technicians&#34;:{&#34;uri&#34;:&#34;technicians&#34;,&#34;methods&#34;:[&#34;GET&#34;,&#34;HEAD&#34;]},&#34;change-password&#34;:{&#34;uri&#34;:&#34;change-password&#34;,&#34;methods&#34;:[&#34;GET&#34;,&#34;HEAD&#34;]},&#34;reset.password&#34;:{&#34;uri&#34;:&#34;c ---------- &lt;/script&gt; </code></pre> <p>有什么方法可以在 app.js 中重新定位这个 Ziggy 对象或使其不那么明显吗?根据 <a href="https://github.com/tighten/ziggy" rel="noreferrer">Ziggy</a> 文档和此处尝试的答案,我尝试将其导入 app.js,a 但它不起作用。</p> <blockquote> <p>未捕获的类型错误:无法读取未定义的属性“原型” 在 Object.inherits (app.js:124712) 在对象。 (应用程序.js:68991) 在对象../node_modules/irc/lib/irc.js (app.js:69342) 在 <strong>webpack_require</strong> (app.js:64) 在对象../node_modules/ziggy/index.js (app.js:140181) 在 <strong>webpack_require</strong> (app.js:64) 在模块../resources/js/app.js (app.js:141504) 在 <strong>webpack_require</strong> (app.js:64) 在 Object.0 (app.js:142081) 在 <strong>webpack_require</strong> (app.js:64)</p> </blockquote> <p><strong>___________________________设置______________________________________</strong></p> <p>//后端</p> <pre><code>$ php artisan ziggy:generate File generated! </code></pre> <p>// 示例 /resources/js/ziggy.js 文件 </p> <pre><code>const Ziggy = {&#34;url&#34;:&#34;http:\/\/127.0.0.1:8787&#34;,&#34;port&#34;:8787,&#34;defaults&#34;:{},&#34;routes&#34;:{&#34;debugbar.openhandler&#34;:{&#34;uri&#34;:&#34;_debugbar\/open&#34; /*..... All named routes as expeted */ if (typeof window !== &#39;undefined&#39; &amp;&amp; typeof window.Ziggy !== &#39;undefined&#39;) { for (let name in window.Ziggy.routes) { Ziggy.routes[name] = window.Ziggy.routes[name]; } } export { Ziggy }; </code></pre> <p>///resources/js/app.js</p> <pre><code>require(&#39;./bootstrap&#39;) import Vue from &#39;vue&#39; import VueMeta from &#39;vue-meta&#39; import PortalVue from &#39;portal-vue&#39; import { App, plugin } from &#39;@inertiajs/inertia-vue&#39; import { InertiaProgress } from &#39;@inertiajs/progress/src&#39; // Ziggy start here import route from &#39;ziggy&#39;; import { Ziggy } from &#39;./ziggy&#39;; Vue.mixin({ methods: { route: (name, params, absolute, config = Ziggy) =&gt; route(name, params, absolute, config), }, }); // ziggy end here import { BootstrapVue, IconsPlugin } from &#39;bootstrap-vue&#39; Vue.use(BootstrapVue) Vue.use(IconsPlugin) import &#39;bootstrap/dist/css/bootstrap.css&#39; import &#39;bootstrap-vue/dist/bootstrap-vue.css&#39; import { mixins } from &#39;vue-chartjs&#39; import TreeBrowser from &#39;./Pages/globalComponents/TreeBrowser.vue&#39; //Vue.config.productionTip = false Vue.mixin({ methods: { route: window.route } }) Vue.use(plugin) Vue.use(PortalVue) Vue.use(VueMeta) Vue.component(&#39;TreeBrowser&#39;, TreeBrowser) InertiaProgress.init() let app = document.getElementById(&#39;app&#39;) new Vue({ metaInfo: { titleTemplate: (title) =&gt; title ? `${title} - FNV` : &#39;FNV yours&#39; }, render: h =&gt; h(App, { props: { initialPage: JSON.parse(app.dataset.page), resolveComponent: name =&gt; import (`./Pages/${name}`).then(module =&gt; module.default), }, }), }).$mount(app) </code></pre> <p> // /webpack.mix.js</p> <pre><code>const mix = require(&#39;laravel-mix&#39;); const path = require(&#39;path&#39;); mix.js(&#39;resources/js/app.js&#39;, &#39;public/js&#39;) .sass(&#39;resources/sass/app.scss&#39;, &#39;public/css&#39;); mix.webpackConfig({ resolve: { alias: { ziggy: path.resolve(&#39;vendor/tightenco/ziggy/dist&#39;), }, }, }); </code></pre> <p>Login.vue 中 ziggy ex 的使用</p> <pre><code>this.$inertia.post(this.route(&#39;login.attempt&#39;), data, { onStart: () =&gt; this.sending = true, onFinish: () =&gt; this.sending = false, }) ``` </code></pre> </question> <answer tick="false" vote="9"> <p>这里是 Ziggy 的维护者。 <a href="https://stackoverflow.com/a/66177021/6484459">FightInGlory 的答案</a>是正确的。</p> <p>运行<pre><code>php artisan ziggy:generate</code></pre>。</p> <p>然后,在您的 <pre><code>webpack.mix.js</code></pre> 文件中:</p> <pre><code>const path = require(&#39;path&#39;); // Mix v6 mix.alias({ ziggy: path.resolve(&#39;vendor/tightenco/ziggy/dist&#39;), }); // Or, Mix v5 mix.webpackConfig({ resolve: { alias: { ziggy: path.resolve(&#39;vendor/tightenco/ziggy/dist&#39;), }, }, }); </code></pre> <p>然后,在您要使用 Ziggy 的文件中:</p> <pre><code>import route from &#39;ziggy&#39;; // Change &#39;./ziggy&#39; to the relative path to the file generated above, usually resources/js/ziggy.js import { Ziggy } from &#39;./ziggy&#39;; // ... route(&#39;posts.show&#39;, 1, undefined, Ziggy); </code></pre> <p>如果您使用 Vue,创建一个全局 mixin 会很有帮助,这样您就不需要每次都将 <pre><code>Ziggy</code></pre> 作为第四个参数传递。 <a href="https://github.com/tighten/ziggy#vue" rel="noreferrer">文档中</a>有一个如何设置的示例。</p> <p>如果仍然不起作用,请随时提交问题并详细说明您的设置!</p> </answer> <answer tick="true" vote="4"> <p>如果您不使用 Blade,或者不想使用 @routes 指令,Ziggy 提供了一个 artisan 命令来将其配置和路由输出到文件:php artisan ziggy:generate</p> <pre><code>import route from &#39;ziggy&#39;; import { Ziggy } from &#39;./ziggy&#39;; Vue.mixin({ methods: { route: (name, params, absolute, config = Ziggy) =&gt; route(name, params, absolute, config), }, }); </code></pre> <p>您可以选择创建一个 webpack 别名,以便更轻松地导入 Ziggy 的核心源文件</p> <pre><code>// webpack.mix.js // Mix v6 const path = require(&#39;path&#39;); mix.alias({ ziggy: path.resolve(&#39;vendor/tightenco/ziggy/dist&#39;), }); // Mix v5 const path = require(&#39;path&#39;); mix.webpackConfig({ resolve: { alias: { ziggy: path.resolve(&#39;vendor/tightenco/ziggy/dist&#39;), }, }, }); </code></pre> <p>这意味着您应该更改此处的路径“.ziggy”</p> <pre><code>import { Ziggy } from &#39;./ziggy&#39;; </code></pre> </answer> <answer tick="false" vote="2"> <p>在 Middleware/HandleInertiaRequests.php 上注释或删除 Ziggy 数组,如下所示:</p> <pre><code>public function share(Request $request) { return array_merge(parent::share($request), [ &#39;auth&#39; =&gt; [ &#39;user&#39; =&gt; $request-&gt;user(), ], // &#39;ziggy&#39; =&gt; function () { // return (new Ziggy)-&gt;toArray(); // }, ]); } </code></pre> </answer> </body></html>

回答 0 投票 0

如何在 Laravel 中添加响应 HTTP 数据?

现在为了获取数据,我从控制器调用方法,该方法以 JSON 形式返回数据: 返回响应()->json([$data]); 我可以在此响应中添加全局数据吗?并合并这个$data? 例如我有

回答 2 投票 0

从集合中查询一对一关系

问题是我需要从集合中提取集合。我已经设置了模型和数据库,因此这些关系有效: 一个用户可以进行多次协商 谈判有一个

回答 2 投票 0

如何使用 Laravel 5 中图像上传字段存在的验证规则

我使用 Laravel 5 在更新中,创建请求文件 公共函数规则() { 返回 [ '图像' => '必需', '描述' => '必需', '链接' => '必需', ...

回答 2 投票 0

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

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

回答 3 投票 0

激活一些强化页面用于生产,其他页面用于测试

我在测试服务器和生产服务器上有一个带有 fortify 的 laravel 8x jetstream 版本。 测试:prj_l8xtest.com 制作:prj_l8xprod.com 我想激活或停用一些制作的页面

回答 1 投票 0

如何在 Laravel 5.2 中添加额外的登录条件逻辑

我只是想说如果用户不活跃,则不允许登录。我已经制作了如下控制器,我不确定我缺少什么或者我还需要在这里做什么才能完成这项工作! 我只是想说如果用户不活跃,则不允许登录。我已经制作了如下控制器,我不确定我缺少什么或者我还需要在这里做什么才能完成这项工作! <?php namespace App\Http\Controllers\Auth; use Illuminate\Auth\Authenticatable; use Illuminate\Foundation\Auth\AuthenticatesUsers; use App\User; use Validator; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ThrottlesLogins; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; class AuthController extends Controller{ use AuthenticatesAndRegistersUsers, ThrottlesLogins; protected $redirectTo = '/home'; public function __construct() { $this->middleware($this->guestMiddleware(), ['except' => 'logout']); } protected function validator(array $data) { return Validator::make($data, [ 'name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6|confirmed', ]); } protected function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); } public function authenticate() { if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) { // Authentication passed... return redirect()->intended('dashboard'); } } } 我的想法是authenticate()方法应该可以解决问题! 以下代码适用于我的案例: protected function getCredentials(Request $request) { return [ 'email' => $request->input('email'), 'password' => $request->input('password'), 'active' => true ]; } 对于 Laravel 5.3 需要在 LoginController 中添加以下代码 protected function credentials(Request $request) { return [ 'email' => $request->input('email'), 'password' => $request->input('password'), 'active' => true ]; } 我认为你应该创建方法来检查用户是否通过了你的凭据,这是我的建议: protected function getCredentials(Request $request) { return [ 'username' => $request->input('email'), 'password' => $request->input('password'), 'active' => true ]; } 以及您的登录方式: public function login(Request $request) { $this->validate($request,['email' => 'required|email','password' => 'required']); if (Auth::guard()->attempt($this->getCredentials($request))){ //authentication passed } return redirect()->back(); } 希望你得到基本的想法。 在LoginController.php文件中编写这个函数 protected function credentials(Request $request) { $extraFields = [ 'user_type'=> 'customer', 'user_entry_status' => 1 ]; return array_merge($request->only($this->username(), 'password'), $extraFields); } 转到此路径: your-project-folder/vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php $credentials=$request->only($this->loginUsername(), 'password'); $credentials['status'] = '1'; return $credentials; 更改 getCredantials 工作正常,但最好让用户知道帐户已暂停(凭据正常,但帐户状态不行)。您可以轻松地将 Auth/LoginController.php 中的登录方法重写为您自己的副本,将您自己的逻辑添加到登录过程并引发自己的异常。 在Auth/LoginController.php中创建登录和sendAccountBlocked函数 /*load additional classes to LoginController.php*/ use Illuminate\Http\Request; use Illuminate\Validation\ValidationException; use Auth; public function login(Request $request){ // $this->validateLogin($request); // // If the class is using the ThrottlesLogins trait, we can automatically throttle // the login attempts for this application. We'll key this by the username and // the IP address of the client making these requests into this application. if (method_exists($this, 'hasTooManyLoginAttempts') && $this->hasTooManyLoginAttempts($request)) { $this->fireLockoutEvent($request); return $this->sendLockoutResponse($request); } if ($this->attemptLogin($request)) { //check user status if (Auth::user()->user_status == 'A') return $this->sendLoginResponse($request); // if user_status != 'A' raise exception else { $this->guard()->logout(); return $this->sendAccountBlocked($request); } } // If the login attempt was unsuccessful we will increment the number of attempts // to login and redirect the user back to the login form. Of course, when this // user surpasses their maximum number of attempts they will get locked out. $this->incrementLoginAttempts($request); return $this->sendFailedLoginResponse($request); // }// protected function sendAccountBlocked(Request $request){ throw ValidationException::withMessages([ $this->username() => ['Your account was suspended.'], ]); }

回答 5 投票 0

Laravel雄辩问题:方法不存在

我有 2 张桌子,客户和公司 每个公司有多个客户,每个客户有一个公司 这是我的模型: 类 Client 扩展 Model { 公共职能公司(){ 返回...

回答 2 投票 0

“方法类别不存在。”在 Laravel

这个错误是什么? 方法类别不存在。 文章控制器.php 公共函数存储(ArticleRequest $request) { $imagesUrl = $this->uploadImages($request->file('images')); ...

回答 1 投票 0

附加经过身份验证的用户来创建

我正在尝试将当前登录的用户附加到此请求,以便我可以将其保存在数据库中。有人可以指出我正确的方向吗? 公共功能商店(

回答 1 投票 0

在播种或迁移表时如何向控制台提供输出?

我十月份有一个插件,我正在创建必要的表并根据文档播种它们。 我希望在执行此操作时提供控制台输出,以便我可以调试我正在设置的进程并捕获...

回答 2 投票 0

将数组中的行数据按位置附加到 Laravel 集合中的项目

我需要加入单独的数组,我正在使用 Laravel 5.3 Collections。我有两个独立的对象。我从谷歌地图中获取城市和街道地址之间的距离矩阵的一个对象......

回答 1 投票 0

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