[英]Laravel 5.2 extra column in table Users
使用Laravel 5.2,我在数据库表“用户”中添加了一列“代码”,我想在控制器中过滤DB :: table结果。
我在视图中渲染行。 但是当我添加where子句-> where('code',$ codevar)时,会收到未找到Auth的错误消息。 怎么样
表用户
id email code password
-------+----------------------------+------------+-------------------
1 admin@admin.com (logged) 007 $2y$10$azWc9kKFU/...
2 user@user.com 666 $2y$10$azWc9kKFU/...
报告表
code date price
-------+------------------+--------
007 2016-01-20 $10.20
666 2016-02-22 $58.00
输出量
code month price
-------+------------------+--------
007 01 $10.20
666 02 $58.00
预期产量
code month price
-------+------------------+--------
007 01 $10.20
MyController.php
<?php
use DB;
use Auth;
namespace LaravelAcl\Authentication\Controllers;
use Illuminate\Http\Request;
use LaravelAcl\Library\Form\FormModel;
use LaravelAcl\Authentication\Models\Permission;
use LaravelAcl\Authentication\Validators\PermissionValidator;
use LaravelAcl\Library\Exceptions\JacopoExceptionsInterface;
use View, Redirect, App, Config;
class ResumenesController extends Controller
{
public function getList()
{
$user = \Auth::user();
$codevar = \Auth::user()->code;/// maybe like this
$rows= \DB::table('reports')
->select('*', \DB::raw('MONTH(date) as month)')
->where('code', $codevar)*
->orderBy('month','DESC')
->paginate(15);
return View::make('client.report.list', compact('rows','codevar', 'user'));
}
我如何检索\\ Auth :: user()或Auth :: user()->代码。 只有我想要获得用户表的这些额外列作为过滤器表结果...
有学习的想法吗?
您可以使用auth()->user()
全局帮助器,也可以使用Auth外观,但是请记住,在检索经过身份验证的用户时,您将始终获得所有字段。
就像克里斯蒂安·格德斯(Christian Gerdes)在评论中说的那样,在顶部导入Auth门面,然后删除反斜杠。 对数据库外观执行相同的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.