Scott Blog


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 搜索

Laravel Api Resource

发表于 2020-04-19 | 分类于 Tech

Laravel 不使用第三方包,实现 API 功能。

参考:

  • Laravel API资源
  • Include机制
  • 预加载

生成资源

1
2
3
4
5
# 生成 User资源
php artisan make:resource User

# 生成 User资源集合
php artisan make:resource UserCollection

app/Http/Resources/User.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

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\Book as BookResource;

class User extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
// $this 代表 User 实例
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->phone,

];
}
}

阅读全文 »

LinkedList

发表于 2019-12-19 | 分类于 Tech

LinkedList 使用快慢指针寻找链表的中点,遍历一遍链表。
参考链接:

  • middle-of-the-linked-list

快慢指针

阅读全文 »

vue.js

发表于 2019-12-09 | 分类于 Tech

Laravel with Vue.js

参考链接:

  • 通过 Laravel 创建一个 Vue 单页面应用
  • Vue-router

Laravel中使用vue.js实现前后端分离。Laravel 后端只提供 api供 Vue.js 前端调用。

Laravel 配置

1
$ laravel new todo

项目的入口 spa 视图

1
$ php artisan make:controller SpaController

Http/Controllers/SpaController.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SpaController extends Controller
{
public function index()
{
// 项目的入口
return view('spa');
}
}

阅读全文 »

Laravel with Dingo

发表于 2019-07-13 | 分类于 Tech

Laravel使用Dingo扩展包
参考:

  • 安装Dingo
  • include机制
  • 回复列表

安装 Dingo

1
$ composer require dingo/api
阅读全文 »

微信小程序微信登录

发表于 2019-06-22 | 分类于 Tech

微信小程序 微信登录
参考:

  • jwt-auth
  • 小程序登录

使用微信登录

jwt

JWT 由头部(header)、载荷(payload)与签名(signature)组成.客户端请求的时候在 Header 中携带 Token,服务器获取 Token 后,进行 base64_decode 即可获取数据进行校验

阅读全文 »

微信小程序手机登录

发表于 2019-06-15 | 分类于 Tech

微信小程序分别使用手机号和微信登录
参考:

  • easy-sms
  • 短信提供商
  • 手机注册验证码
  • 图片验证码

使用手机登录

发送手机短信

安装easy-sms

1
2
3
$ composer require "overtrue/easy-sms"
# config中添加easysms.php 配置文件
$ touch config/easysms.php
阅读全文 »

Laravel Passport

发表于 2019-06-01 | 分类于 Tech

使用Laravel Passport 实现api用户认证

参考:

  • 使用Laravel Passport

Passport配置

1
2
3
4
5
6
composer require laravel/passport

//表迁移,生成oauth相关的表
php artisan migrate

php artisan passport:install
阅读全文 »

laravel factories

发表于 2019-05-26 | 分类于 Tech

Laravel 数据填充

参考:

  • 假数据填充
  • 数据填充
  • 模型工厂
  • make-your-laravel-seeder-using-model-factories
1
2
3
//文件名单数
php artisan make:factory ThreadFactory --model=Thread
php artisan make:factory ReplyFactory --model=Reply
阅读全文 »

Hexo Blog

发表于 2019-05-19 | 分类于 Tech

Hexo 博客的搭建

参考:

  • Hexo
  • git多人协作
  • theme nexT
  • theme nexT github

安装前提

  • Node.js
  • git

npm install -g hexo-cli

阅读全文 »

Laravel Notifications toDatabase

发表于 2019-05-18 | 分类于 Tech

参考:
消息通知

Prepare notification database

1
2
3
4
5
php artisan notifications:table
php artisan migrate

#add users table notification_count column
php artisan make:migration add_notification_count_to_users_table --table=users

Generate notification class

1
php artisan make:notification
阅读全文 »
12

Scott Shen

记录自己的点滴

14 日志
1 分类
14 标签
RSS
GitHub E-Mail
© 2019 — 2020 Scott Shen
由 Hexo 强力驱动
|
主题 — NexT.Pisces v5.1.4