laravel 笔记
  • Introduction
  • 说明
  • Laravel 基础
    • 安装与配置
    • 目录结构
    • 路由配置
    • MVC 配置
    • 数据库操作
      • DB façade 方式
      • 查询构造器方式
      • Eloquent ORM 方式
      • 数据库迁移
      • 数据填充
    • 请求和响应和重定向
    • Session
    • 中间件
    • 其他
      • Artisan 命令行
  • Laraval 源码分析
    • 请求到响应的生命周期
      • 程序启动准备
      • 请求实例化
      • 处理请求
      • 响应的发送与程序终止
    • 路由
    • 补充知识点
      • 反射机制
      • Closure 类
  • 资料
  • 核心思想
    • 服务容器
    • 服务提供者
    • Facades(门脸模式)
  • 开发笔记
  • Artisan 命令
  • yarn
Powered by GitBook
On this page
  • 配置访问路由
  • 控制器

Was this helpful?

  1. Laravel 基础
  2. 数据库操作

DB façade 方式

配置访问路由

routes/web.php文件中配置

Route::any('FacadesTest', ['uses' => 'StudentController@FacadesTest']);

控制器

文件示例App\Http\Controllers\StudentController

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{

    public function FacadesTest()
    {
        // 新增
       $bool = DB::insert('insert into student(name, age) values(?, ?)',
           ['imooc', 19]);
       var_dump($bool);

        // 更新
       $num = DB::update('update student set age = ? where name = ?',
           [20, 'sean']);
       var_dump($num);

        // 查询
       $students = DB::select('select * from student where id > ?',
           [1001]);
       dd($students);

        // 删除
        $num = DB::delete('delete from student where id > ?', [1001]);
        var_dump($num);

    }
}
Previous数据库操作Next查询构造器方式

Last updated 5 years ago

Was this helpful?