我爲管理ajax請求編寫控制器。我編寫了用於檢查用戶登錄的構造方法if
阻止工作正常但總是返回user.setting
查看並返回構造不工作。通過ajax的Laravel身份驗證
控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Auth;
class AjaxController extends Controller {
public function __construct() {
if (Auth::check() == FALSE) {
return view('errors.notLogin');
}
}
public function settings() {
return view('user.setting');
}
}
路線:
Route::post('ajax/settings', '[email protected]');
JS:
acc_settings = function (url) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: url,
type: 'POST',
data: 'settings=settings',
success: function (data) {
$("#ajax").html(data);
}
});
};