欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

laravel框架分组控制器和分组路由实现方法示例

程序员文章站 2024-02-07 09:27:40
本文实例讲述了laravel框架分组控制器和分组路由实现方法。分享给大家供大家参考,具体如下:路由route::group(['domain' => 'laravel.8g.com','name...

本文实例讲述了laravel框架分组控制器和分组路由实现方法。分享给大家供大家参考,具体如下:

路由

route::group(['domain' => 'laravel.8g.com','namespace' => 'admin'],function() {
  route::get('/admin/login','logincontroller@login');
  route::post('/admin/signin','logincontroller@signin');
});

控制器(http\controllers\admin\logincontroller.php)

<?php
/**
 * created by phpstorm.
 * user: administrator
 * date: 2017/11/5
 * time: 14:08
 */
namespace app\http\controllers\admin;
use app\user;
use illuminate\http\request;
use app\http\controllers\controller;
class logincontroller extends controller
{
  public function login()
  {
    return view("login/login");
  }
  public function signin(request $request)
  {
    var_dump($request->all());
    $username = $request->input("username");
    $password = $request->input('password');
    var_dump($username);
    var_dump($password);
    return view("login/signin");
  }
}

模板(reeources\views\login\login.blade.php)

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>test</title>
</head>
<body>
  <form method="post" action="{{ url('/admin/signin') }}">
    <input name="username" type="text" value=""/>
    <input name="password" type="text" value=""/>
    <input type="hidden" name="_token" value="{{ csrf_token() }}" />
    <input type="submit" value="提交">
  </form>
</body>
</html>

{{ csrf_field() }} //这个是直接输出一个input标签

登录验证

use illuminate\support\facades\auth;

$res = auth::attempt(['name' => $username, 'password' => $password]);

$res = auth::attempt(['email' => $email, 'password' => $password]);