Laravel 5.1.11中的身份验证 - 它继续使用默认的“用户”模型并搜索“用户”选项卡

时间:2016-02-23 10:30:39

标签: authentication laravel-5.1 laravel-5.2

我创建了一个自定义用户模型,带有自定义受保护的$ table名称。 但是控制器中的尝试方法会继续搜索并使用默认方法('用户'模型和'用户'标签) 奇怪的是,在Laravel 5.2中它起作用。 也许只是我,我错过了一个愚蠢的事情,但为什么它不适用于5.1? 谢谢你的时间。

型号:

namespace App;
use Illuminate\Database\Eloquent\Model;

class CustomUser extends Model
{
    protected $table ='myuserstab';
}

控制器:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Auth;
use App\CustomUser;

class loginController extends Controller
{

    public function login(Request $request)
    {

        $username= $request['username'];
        $password = $request['password'];
        if(Auth::attempt(['username'=>$username, 'password'=>$password]))
        {
          doSomething...
        }
        else 
        {
         doSomethingelse...
        }
    }
...
}

1 个答案:

答案 0 :(得分:1)

我认为您要更改 $('.userPhoto img').each(function () { $this = $(this); var $height = $this.height(); console.log($height); $this.parent().parent().find(".featuredPlayer").css("height", $height); }); $('.userSummary > a').click(function () { $(this).parents().find('.featuredPlayer').addClass('show'); $(this).parents().siblings().find('.featuredPlayer').removeClass('show'); }); $('.jp-stop').click(function () { $(this).parents().find('.featuredPlayer').removeClass('show'); }); var container = $('nav#left').jScrollPane({ showArrows: false, autoReinitialise: false }); var jsp = container.data('jsp'); $(window).on('resize', function () { jsp.reinitialise(); }); // Local copy of jQuery selectors, for performance. var my_jPlayer = $("#jquery_jplayer"), my_trackName = $("#jp_container .track-name"), my_playState = $("#jp_container .play-state"), my_extraPlayInfo = $("#jp_container .extra-play-info"); // Some options var opt_play_first = false, // If true, will attempt to auto-play the default track on page loads. No effect on mobile devices, like iOS. opt_auto_play = true, // If true, when a track is selected, it will auto-play. opt_text_playing = "Now playing", // Text when playing opt_text_selected = "Track selected"; // Text when not playing // A flag to capture the first track var first_track = true; // Change the time format $.jPlayer.timeFormat.padMin = true; $.jPlayer.timeFormat.padSec = true; // $.jPlayer.timeFormat.sepMin = " min "; // $.jPlayer.timeFormat.sepSec = " sec"; // Initialize the play state text my_playState.text(opt_text_selected); // Instance jPlayer my_jPlayer.jPlayer({ ready: function () { $("#jp_container .track-default").click(); }, timeupdate: function (event) { my_extraPlayInfo.text(parseInt(event.jPlayer.status.currentPercentAbsolute, 10) + "%"); }, play: function (event) { my_playState.text(opt_text_playing); }, pause: function (event) { my_playState.text(opt_text_selected); }, ended: function (event) { my_playState.text(opt_text_selected); }, //swfPath: "../../dist/jplayer", cssSelectorAncestor: "#jp_container", supplied: "mp3", wmode: "window", smoothPlayBar: true }); // Create click handlers for the different tracks $("#jp_container .track").click(function (e) { my_trackName.text($(this).attr('title')); my_jPlayer.jPlayer("setMedia", { mp3: $(this).attr("href") }); my_jPlayer.jPlayer("play"); first_track = false; $(this).blur(); return false; }); $('.profilePlaylist ul li ul li a.track').click(function (e) { $('.profilePlaylist ul li ul').removeClass('playing'); var playing = $(this).parent().parent().parent().find('ul'); var notplaying = $(this).parent().parent().parent().find('ul.playing'); playing.toggleClass('playing'); notplaying.toggleClass('playing'); e.preventDefault(); }); });

中的设置

config/auth.php

值得从文档中阅读:

https://laravel.com/docs/5.1/authentication#introduction-database-considerations

5.2支持多个身份验证提供程序,所以也许您可以同时在那里工作?如果您查看5.2中的配置文件,您会看到以下内容:

return [

    'driver' => 'eloquent',

    // change this to App\CustomUser::class, or 
    'model' => App\User::class,whatever your model namespace is

     // change this to 'myuserstab'
    'table' => 'users',

];

您可能需要考虑使用自己的自定义模型进行身份验证的含义,因为用户模型设置为执行您可能需要自己解决的许多开箱即用的事情。浏览文档应该为您澄清这些注意事项。