问题标签 [laravel-5.8]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
797 浏览

eloquent - Laravel 5.8 在每个用户的不同数据库上启动 DB::beginTransaction()

我有一个应用程序,用户拥有自己的数据库。我正在创建一个包含关系的记录保存(因此更新了两个表),我想用DB::transaction(). 唯一的问题是数据库名称必须逐个更改用户。

包含预期的$user->db_name数据,并且可以很好地与其他选择查询一起使用。

如果我这样做,它会失败Call to a member function beginTransaction() on null

如果我这样做并在第二个创建语句上强制失败,它会将第一次创建的记录保留在表中。

如何在针对用户数据库的故障回滚的情况下实现数据库更改和事务?谢谢

0 投票
1 回答
1208 浏览

laravel - 带有条件的laravel分页

我有分页问题,​​到目前为止,我查看了文档,但在那里找不到。我还查看了有关堆栈溢出的其他帖子,但在这种情况下,它们不具备我的条件。那么我如何对if语句进行分页,因为我得到了错误

未定义属性:Illuminate\Pagination\LengthAwarePaginator::$threads

因为当你分页时,你需要像这样直接从模型中取出model::paginate()它,那么在这种情况下你怎么做呢?

控制器

那么如何正确分页$tag = Tag::find($request->tags)->paginate(10);呢?

tag如果单击该链接,则生成控制器从中获取链接的刀片

更新

var_dump($request->tags);在控制器滴string(1) "2"

0 投票
0 回答
647 浏览

maatwebsite-excel - 如何修复 Laravel Excel 中不允许“MongoDB\Driver\Manager”的序列化

我正在尝试使用队列导出 mongoDB 模型,但总是返回异常“不允许序列化 'MongoDB\Driver\Manager'”。我在 github ( https://github.com/Maatwebsite/Laravel-Excel/issues/1760 ) 中发现了这个问题,但我不知道问题是否已解决,或者如果已解决,如何将更正应用于我的代码.

我的环境:php-7.2、laravel-5.8.7、laravel excel-3.1。

我的工作类别:

0 投票
1 回答
1395 浏览

php - 使用 PHP 更新 .env 值

我知道你们中的一些人可能认为这会导致安全问题。

但 ...

我只想更新2特定的标志,因为有时我想查看报告,有时我不想。如果我有办法更新这些标志——只要我想通过 EMAIL 或 SMS 查看报告,我就可以通过 Apple iPhone Shortcut 连接一个切换该功能的路由。


我试过了

创建了一条路线

叫它

这将触发此功能

我不断收到,true因为在我的 .env 中似乎没有更新

我想有MAIL_REPORT=false

注意:我已经跑了:sudo chmod 777 .env

如何进行并进一步调试呢?

0 投票
2 回答
257 浏览

php - Laravel:如何访问登录用户的唯一 ID 并在数据库查询中使用它?

我正在制作一个大学管理网站,教授登录并为他们正在教的学生分配分数。

我的数据库中有一个名为“IA_Marks”的表:

在我的数据库中还有一个名为“Classroom_Mapper”的表,它可以帮助将教授映射到教室,其中包含一个主题:


我的问题:

我希望从Classroom_MapperSubject_Code表中获取, Semester,Division字段以便我可以使用它从IA_Marks表中获取, , 。Student_IDNameMarks1,2,3

要从Classroom_Mapper表中获取 3 个字段,我需要该Prof_ID字段,该字段对每个教授都是唯一的。

每个教授都使用他的Prof_ID.

  1. 如何获取 Prof_ID?
  2. 当我获取 Prof_ID 时,如何将Classroom_Mapper中的其他 3 个字段提取到我的控制器中?

我需要获取这些字段,以便我可以缩小IA_Marksselect上的查询结果,它当前显示整个表。

这是我当前的代码:它显示了完整的表格,而不仅仅是显示所需的记录:

用户定义控制器.php

ia.blade.php


我解决这个问题的想法:(语法肯定是错误的!但我希望你能看到我的目标。)

我只是不知道如何获取这些值!

0 投票
1 回答
1533 浏览

php - Laravel: How to dynamically create and name views?

I am making a website for college administration where professors log in and assign marks to the students they are teaching.

There's a table, called "IA_Marks" in my database:

There's also a table called "Classroom_Mapper" in my database, that helps map a professor to a classroom, with a subject:

This is a method in my controller:

Using this, I can fetch rows that belong to the professor who has logged in.


But, there's a problem.

Say the professor teaches two subjects, in two semesters. Then, the where clause will return multiple results from the mapper table. For example:

output:

8

5

Then the students from both 5th and 8th semester will be shown on his dashboard. Our target semester was, say 5th. Then it'll be a problem.

Registering for a subject, is done as shown here: form screenshot

Let's call the subject being registered in the screenshot "SUBJECT 4". It is a subject for the 5th semester, division A.

I want to dynamically make a button(SUBJECT 4) on the dashboard, which when clicked, sends the semester(5) and division(A) of choice to the controller. Dashboard Screenshot

This button should open a newly made page with name of the subject(subject4.blade.php), where the database table contents for target semester and division(5 and A) will be shown.

How do I make this dynamic view creating button which sends specific info to controller? Is it even possible?

0 投票
1 回答
1070 浏览

php - Laravel 两个控制器和一个模型

我只是在玩弄我的代码,并注意到我的一个控制器正在返回空属性,但另一个正在返回我的数据正常。

我有两个控制器,OneController 和 TwoController,其中包含资源和相同的模型。我使用php artisan make:controller OneController --model==MyModelphp artisan make:controller TwoController --model==MyModel。两个具有相似型号的不同控制器。

都有

但只有OneController@show返回我的数据......

我的链接是这样的

我也跑php artisan route:clear

我将我的更改TwoController@showshow($id),它工作正常,但我不能忽略相同的代码给我不同的结果,我希望我的代码尽可能干净。

Laravel 5.8 中是否有任何规则,您只能在资源上的每个模型使用一个控制器?

我错过了什么吗?

谢谢!

0 投票
3 回答
2330 浏览

laravel - Laravel:如何在视图上动态创建链接按钮?

我正在制作一个教授可以登录的大学管理网站。

我有一个仪表板,应该放置我的动态生成的按钮:(现在它只有虚拟按钮!)

仪表板 由这个视图文件生成,我将很快对其进行修改:


数据库中的表:

  • 该表iamarks包含将显示的数据(学生信息和分数)/subcode/{subcode}缩小为仅分配给当前登录教授的班级中的学生的记录。
  • classroom_mappers是用于将教授映射到具有主题的教室的表格。它确保一个教室只有一位教授特定学科。

当前在我的web.php中的路线:

...这些是我的控制器内部的方法:


我的问题:

为了能够{subcode}在 URL 中动态生成,我想使用数据在仪表板中创建按钮$subcodes。控制器移交$subcodes(一组属于已登录教授的主题代码),这些代码将由该方法制成按钮show()

按钮应具有名称{subcode},单击时应在 URL 中附加与{subcode}.

  1. 如何$subcodes动态使用和制作按钮?
  2. 如何确保为一个用户制作的按钮对另一个用户不可见?
0 投票
1 回答
1912 浏览

laravel - 减少 Laravel 5.8 的 Docker 镜像大小

我需要减少我的 Laravel 5.8 项目的 Docker 映像大小。

我现在有这个

docker-compose.yml

首先我跑了docker-compose up。我的网站正在运行。

然后,我运行了我看到的 docker images

我懂了


尺码有点大193MB+157MB


docker history c404551006c7

人们将如何进行并进一步减小它的大小?

0 投票
2 回答
4185 浏览

php - Laravel 5.8 同步/附加/分离事件

Laravel 5.8应该调度同步、附加和分离事件(https://laravel.com/docs/5.8/releases搜索中间表/数据透视模型事件部分)。

更新:发布此问题后,发行说明已更新(更多信息:https ://github.com/laravel/framework/issues/28050 - https://github.com/laravel/docs/pull/5096)。

我试过了,但是下面的代码抛出了异常:

调用未定义的方法 App\ProjectUser::syncing()

注意:由于 Laravel 5.8 应该调度同步事件,我不想使用外部包。

我试图将引导方法从ProjectUserto移动UserProject但我得到了同样的异常。