我无法访问“仪表板”。存在一些无法访问仪表板的问题

时间:2019-03-27 05:28:31

标签: laravel

我无法访问控制板。我的代码中肯定有一些问题。但是我找不到那些。我检查了很多次。我试了很多当我在登录页面中输入正确的电子邮件和密码时,它会显示相同的消息。

这是web.php文件

Route::get('/admin', 'AdminController@index');
Route::get('/dashboard','AdminController@show_dashboard');
Route::post('/admin-dashboard','AdminController@dashboard');

这是admin_login.blade.php文件

<p class="alart-danger">
<?php
$message=Session::get('message');
if($message){
echo $message;
Session::put('message',null);
}
?>
</p>


<h2>Login to your account</h2>
<form class="form-horizontal" action="{{url('/admin-dashboard')}}" 
method="post">

{{ csrf_field() }}
<fieldset>

这是AdminController.php文件

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use Session;
use Illuminate\Support\Facades\Redirect;
session_start();
class AdminController extends Controller
{
//
public function index()
{
    return view('admin_login');
}
public function show_dashboard()
{
    return view('admin.dashboard');
}
 public function dashboard(Request $request)
{
    $admin_email=$request->admin_email;
    $admin_password=md5($request->admin_password);
    $result=DB::table('tbl_admin')
            ->where('admin_email', $admin_email)
            ->where('admin_password', $admin_password)
            ->first();
            // echo"<pre>";
            // print_r($result);
            // exit();
        if ($result)
        {
            Session::put('admin_name',$result->admin_name);
            Session::put('admin_id',$result->admin_id);
            return Redirect::to('/dashboard');
        }else{
            Session::put('message', 'Email or Password Invalid');
            return Redirect::to('/admin');
        }
}

1 个答案:

答案 0 :(得分:0)

以此替换您的控制器代码,然后检入存储日志

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use Session;
use Log;
class AdminController extends Controller
{
public function index()
{
    return view('admin_login');
}
public function show_dashboard()
{
    return view('admin.dashboard');
}
 public function dashboard(Request $request)
{
    $admin_email=$request->admin_email;
    $admin_password=md5($request->admin_password);
    $result=DB::table('tbl_admin')
            ->where(['admin_email' => $admin_email,'admin_password' => $admin_password])
            ->first();
        Log::info('result is '.$result);    // just for checking result (storage/logs)    
        if (!empty($result))
        {
            Session::put('admin_name',$result->admin_name);
            Session::put('admin_id',$result->admin_id);
            return redirect()->to('/dashboard');
        }else{
            Session::put('message', 'Email or Password Invalid');
            return return redirect()->to('/admin');
        }
}