如何通过用户身份验证在laravel中通过uri id查询db?

时间:2016-07-27 20:48:49

标签: php laravel-5 laravel-5.2

我刚刚在这里完成了中级laravel教程:https://laravel.com/docs/5.2/quickstart-intermediate,我正试着继续推进。

虽然我可以通过身份验证和用户ID获取所有任务:

var cometD = $.cometd;

var isConnected = false;

var rcvHandshake = function(hndValue) {
    console.log("Received handshake. Success flag is " + hndValue.successful);
}

var amConnected = function(msgConnect) {
    if(cometD.isDisconnected())
    {
        isConnected = false;
        console.log("Server connection not established!");
    }
    else
    {
        var prevconnected = mySelf.isConnected;

        // This checks whether or not the connection was actually successful
        isConnected = msgConnect.successful === true;
        if((prevconnected == false) && (isConnected == true))
        {
            console.log("Connected to the server!");
            cometD.addListener("/service/output",updateOutput);
        }
        else if((prevconnected == true) && (isConnected == false))
        {
            console.log("Connection to server has ended!")
        }
    }

}

var startUp = function() {
    console.log("Starting up...");

    var cometURL = $(location).attr('origin') + "/tester/cometd";
     cometD.configure({
        url: cometURL,
        logLevel: 'info'
    });

    cometD.addListener('/meta/handshake',rcvHandshake);
    cometD.addListener('/meta/connect',amConnected);

    cometD.handshake({
        "thehash.autohash": "foo-bar-baz-hash"
    });

}

var updateOutput = function(theOut) {
    alert(theOut.data);
}

我想创建一个视图函数...如果我创建一个指向/ task / 7的链接,我将查询有关id为7的任务的信息(例如)&把它发送到视图?

1 个答案:

答案 0 :(得分:1)

定义匹配Route::get("/task/{taskId}", "TaskController@getView"); 网址的路由,如下所示:

TaskController

然后,在getView中,将public function getView($taskId){ $task = \App\Task::where("id", "=", $taskId)->first(); return view("tasks.view")->with(["task" => $task]); } 函数定义为:

taskId

这是通过URL参数传递# initialization >>> lst = [1, 2, 5, 3, -2, -1, 4, 5, 2, 4, 8] >>> n = 3 ,查询数据库以查找匹配记录并返回视图以显示相关信息的最简单方法。

还有更多参与,例如验证记录存在,但这应该可以帮助你。