一、背景
#####最近组里准备搞一个项目,以php lumen框架为基础。由于没有学过php语言更别说lumen框架,于是现在狂补中。
二、学习记录
1.新建controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\User;
use Auth;
class UserController extends Controller
{
public function __construct()
{
//
}
public function index(){
$user = DB::table('users')->get();
$result = DB::select('select * from users');//查询users表
foreach ($result as $res){
echo $res->password . PHP_EOL;//遍历数据库,输出users.password
}
return view('index',['users' => $user]);//返回视图
}
}
2.新建UserMiddleware
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/29 0029
* Time: 16:49
*/
namespace App\Http\Middleware;
class UserMiddleware
{
/*public function handle($request,Closure $next){
echo 11;
return $next($request);
}*/
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//echo 11;
return $next($request);
}
}
3.新建路由
$router->get('user', '[email protected]');
//url后带user时调用user方法
4.新建index视图
//resources/view下新建视图,经测试视图默认名为xxx.blade.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/30 0030
* Time: 9:51
*/
//输入逻辑代码
?>