mysql - 将 Controller 在 Blade 文件中获取的值传递给查询

标签 mysql laravel laravel-5 laravel-5.3

我已将 Blade 文件中的 Controller 值获取为 {{ $user->user_name }}。我想传递该值以在同一 Blade 文件中进行查询。

sample.blade.php
{{$user->user_name}}

$test=db::table('department')->where('department.parent_department','=','{{ $user->user_name }}')->get();

最佳答案

你可以像这样使用它,不需要花括号。

$test=DB::table('department')->where('department.parent_department','=',$user->user_name)->get();

关于mysql - 将 Controller 在 Blade 文件中获取的值传递给查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46445006/

相关文章:

php - 使用 League OAuth2 客户端的 Laravel Oauth2 Controller

php - 用laravel迁移一张表,错误 "MySQL server has gone away"和 "Packets out of order"

javascript - Laravel 电子邮件与域名验证两次

php - 从php中的MySQL函数检索返回值

mysql - 查找表格中的所有起始字母

laravel - 目标组 443 给出 Health checks failed with these codes : [502]

php - 如何检查变量在laravel Blade 中是否有数据

laravel - 调用未定义的方法 Illuminate\Notifications\Notification::send()

php - 使用 mysql/php 在两个表上运行两个查询以获得一个结果列表

javascript - 在表中每页显示 50 行,但允许搜索整个表