Example of implementation method of laravel framework packet controller and packet routing

Time:2021-8-25

This paper describes the implementation of packet controller and packet routing in laravel framework. Share with you for your reference, as follows:

route


Route::group(['domain' => 'laravel.8g.com','namespace' => 'Admin'],function() {
  Route::get('/admin/login','[email protected]');
  Route::post('/admin/signin','[email protected]');
});

Controller (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");
  }
}

Template (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 = "submit" >
  </form>
</body>
</html>
{{ csrf_ Field()}} // this directly outputs an input tag

validate logon


use Illuminate\Support\Facades\Auth;

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

or


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

For more information about laravel, readers who are interested can see the special topics on this site: introduction and advanced tutorial of laravel framework, summary of PHP excellent development framework, introduction to PHP object-oriented programming, introduction to PHP + MySQL database operation, and summary of common database operation skills for PHP

I hope this article will be helpful to your PHP Programming Based on laravel framework.