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

时间:2022-09-17 12:55:35

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

路由

?
1
2
3
4
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)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?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)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!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>
?
1
{{ csrf_field() }} //这个是直接输出一个input标签

登录验证

?
1
2
3
use Illuminate\Support\Facades\Auth;
 
$res = Auth::attempt(['name' => $username, 'password' => $password]);

?
1
$res = Auth::attempt(['email' => $email, 'password' => $password]);

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

原文链接:https://www.cnblogs.com/fps2tao/p/7787343.html