小编Xah*_*mal的帖子

Laravel 5.3查询从4个表中获得结果,这些表通过外键连接

我正在使用Laravel 5.3.我有4张桌子.默认Users表.Departments,Position,Employees表.

Users 表有 ID | Email | Password

Departmentstable has ID | Department | User_Id- 这User_Id是外键来自Userstable'sID

Positionstable has ID | Position | Department_Id- 这Department_Id是外键来自Departmentstable'sID

Employeestable has ID | Employee | Position_Id - 这Position_Id是外键来自Positionstable'sID

用户可以拥有多个Departments.Departments可以有多个Positions,Positions可以有多个Employees.因此,如果用户不同,我如何从该用户创建的所有4个表中检索所有数据?

laravel laravel-5 laravel-5.3

6
推荐指数
1
解决办法
108
查看次数

在使用忘记密码发送密码重置电子邮件之前检查用户是否已激活

我正在使用Laravel 5.3. 我已经在 Laravel 的默认Auth. 但是,如果帐户/用户未通过验证电子邮件地址激活,我找不到停止发送密码重置链接的方法。目前,如果用户创建一个帐户并且不验证他/她可以使用密码重置链接登录的电子邮件地址。

这是我在用户表中的内容

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name')->nullable();;
        $table->string('username')->unique();
        $table->string('email')->unique();
        $table->string('company')->nullable();;
        $table->string('password');
        $table->boolean('activated')->default(false);
        $table->rememberToken();
        $table->timestamps();
    });

    Schema::create('user_activations', function (Blueprint $table) {
        $table->integer('user_id')->unsigned();
        $table->string('token')->index();
        $table->timestamp('created_at');
    });
}
Run Code Online (Sandbox Code Playgroud)

更新 我试图通过更新以下功能来做到这一点。但它不起作用

public function reset(Request $request)
{
    if (!$request->activated) {
        return redirect('/');
    } else {
        $this->validate($request, $this->rules(), $this->validationErrorMessages());

        $response = $this->broker()->reset(
            $this->credentials($request), function ($user, $password) {
                $this->resetPassword($user, $password);
            }
        );

        return $response == Password::PASSWORD_RESET
                    ? $this->sendResetResponse($response)
                    : $this->sendResetFailedResponse($request, $response);
    } …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-5.3

5
推荐指数
1
解决办法
3222
查看次数

Laravel 查询中“where”和“orwhere”无法正常工作

我有以下功能 -

public function search_profile(Request $request)
{
    $search_keyword = $request->search;
    $search_user = $request->user;
    $user_public = User::where('username', $request->user)->first();

    $tags_list = Tag::orderBy('tag', 'asc')->get();
    $bookmarks = Bookmark::orderBy('created_at','desc')->where('bookmarker', $search_user)->where('public', '1')->where('tags', 'rlike', $search_keyword)->orwhere('title', 'rlike', $search_keyword)->orwhere('description', 'rlike', $search_keyword)->orwhere('contents', 'rlike', $search_keyword)->paginate(15);
    $bookmarks_all = Bookmark::orderBy('created_at','desc')->where('bookmarker', $search_user)->where('public', '1')->where('tags', 'rlike', $search_keyword)->orwhere('title', 'rlike', $search_keyword)->orwhere('description', 'rlike', $search_keyword)->orwhere('contents', 'rlike', $search_keyword)->get();
    return view('profile_search')->with('bookmark', $bookmarks)->with('tags_list', $tags_list)->with('bookmarks_all', $bookmarks_all)->with('username', $user_public)->with('search_keyword', $search_keyword);
}
Run Code Online (Sandbox Code Playgroud)

但我什至从其他人那里得到了结果bookmarker。例如 - 如果$search_keyword = 'laravel'$serach_user = 'zack'。我也从其他用户那里得到结果。

我是 Laravel 的新手。那么我在查询中做错了什么?

php laravel-5 laravel-query-builder

4
推荐指数
1
解决办法
1万
查看次数

Material Design Lite响应式CSS无法在Mobile/Tablets或Chrome DevTools模拟器中运行

在尝试使用Google Material Design Lite的响应功能时,此代码会在调整浏览器窗口大小时按预期隐藏消息,但当我在Chrome DevTools设备模拟器或实际设备上查看我的页面时,它只会显示"桌面"版本.如何修复HTML?

<html>
  <head>
     <link rel="stylesheet" href="https://storage.googleapis.com/code.getmdl.io/1.0.1/material.indigo-pink.min.css">
  </head>
  <body>
       <div class="mdl-cell--hide-phone mdl-cell--hide-tablet">
          You are on a desktop
       </div>
       <div class="mdl-cell--hide-desktop mdl-cell--hide-tablet">
          You are on a phone
       </div>
       <div class="mdl-cell--hide-desktop mdl-cell--hide-phone">
          You are on a tablet
       </div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

html css responsive-design material-design-lite

2
推荐指数
1
解决办法
1813
查看次数

为什么要使用Math.random()及其功能

我在这里有一段代码:

if (Math.random() < 0.80) {
    var img = $('#img');
}

$(document).mousemove(function(event) {
    var mouse_x = event.pageX;
    var mouse_y = event.pageY;
    $(img).css({
        'top': mouse_y+'px', 
        'left': mouse_x+'px',
        'display' : 'block',
        'position' : 'absolute'
    }); 
});
Run Code Online (Sandbox Code Playgroud)

在这个脚本中,我不明白该if (Math.random() < 0.80)行在做什么.又是如何Math.random()得到它的价值,来自哪里?

javascript random

0
推荐指数
1
解决办法
54
查看次数