解决 Laravel 使用 asset 函数加载资源为 http 协议 / Laravel Horizon 加载资源为 http 协议 作者: Chuwen 时间: 2022-09-14 分类: Laravel 评论 ## 背景 搭建了个 horizon,使用 https 打开,但是打开的界面是下图所示  一看加载的资源是 http 的,那难怪页面无法正常加载  ## 解决办法 在 Google 搜索中,找到了这条答案:https://stackoverflow.com/a/68287406 我认为这才是最标准的解决方案  比起那些去改 `AppServiceProvider.php` 靠谱多了 ### 总结下用法 你只需要在 `.env` 文件里配置号 `ASSET_URL` 环境变量即可,像我这样 ```env ASSET_URL=https://cdn.nowtime.cc ```  ### 完美解决 
解决 GitHub Connect: kex_exchange_identification: Connection closed by remote host 作者: Chuwen 时间: 2022-07-30 分类: Linux 评论 # 背景 想要克隆项目/推送代码到 GitHub 老实错误,检查发现: ```shell ➜ ~ ssh -vvv git@github.com OpenSSH_8.1p1, LibreSSL 2.7.3 debug1: Reading configuration data /Users/chuwen/.ssh/config debug1: /Users/chuwen/.ssh/config line 1: Applying options for * debug1: /Users/chuwen/.ssh/config line 6: Applying options for github.com debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 47: Applying options for * debug1: Executing proxy command: exec nc -v -x 127.0.0.1:7890 github.com 443 debug1: identity file /Users/chuwen/.ssh/id_rsa type 0 debug1: identity file /Users/chuwen/.ssh/id_rsa-cert type -1 debug1: identity file /Users/chuwen/.ssh/id_dsa type -1 debug1: identity file /Users/chuwen/.ssh/id_dsa-cert type -1 debug1: identity file /Users/chuwen/.ssh/id_ecdsa type -1 debug1: identity file /Users/chuwen/.ssh/id_ecdsa-cert type -1 debug1: identity file /Users/chuwen/.ssh/id_ed25519 type -1 debug1: identity file /Users/chuwen/.ssh/id_ed25519-cert type -1 debug1: identity file /Users/chuwen/.ssh/id_xmss type -1 debug1: identity file /Users/chuwen/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_8.1 Connection to github.com port 443 [tcp/https] succeeded! kex_exchange_identification: Connection closed by remote host ``` # 解决方案 最后找到[一篇文章](https://idreamshen.github.io/posts/github-connection-closed/ "一篇文章")解决了这个问题。 只需要在 `~/.ssh/config` 配置以下项目即可 ```config Host github.com HostName ssh.github.com User git Port 443 ``` 如果想要配置代理可以这样: ```config Host github.com HostName ssh.github.com User git Port 443 # 走 HTTP 代理 # ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080 # 走 socks5 代理(如 Shadowsocks) ProxyCommand nc -v -x 127.0.0.1:7890 %h %p ``` ## 最终解决了问题 ```shell ➜ ~ ssh -T git@github.com Connection to ssh.github.com port 443 [tcp/https] succeeded! Hi PrintNow/react-i18next-base-usage! You've successfully authenticated, but GitHub does not provide shell access ```
Laravel Middleware(中间件) 设置登录信息(User Model) 作者: Chuwen 时间: 2022-06-29 分类: Laravel,PHP 评论 Laravel Middleware(中间件) 设置登录信息(User Model),然后在其它地方使用如 Controller(控制器) ### UserAdminAuthGuard 中间件 ```php firstOrFail()); return $next($request); } } ``` ### UserController - HTTP 控制器 ```php
Laravel 控制器测试 作者: Chuwen 时间: 2022-06-02 分类: Laravel,PHP 评论 ## 新建控制器名字为 ForExampleController.php ```php get('domain')) { return response([ 'code' => 400, 'msg' => '错误的参数', ]); } return response([ 'code' => 200, 'msg' => '验证通过', ]); } } ``` ## 新建测试文件名字为 ForExampleControllerTest.php ```php 'nowtime.cc', ]); $forExampleController = new ForExampleController(); $res = json_decode($forExampleController->index($request)->getContent(), true); self::assertEquals(200, $res['code']); } } ``` 运行测试结果: 
Laravel mix + TailwindCSS 运行 npm run watch 无限重新编译 CSS 作者: Chuwen 时间: 2022-05-21 分类: JavaScript 评论 先说答案,参考的是:https://github.com/laravel-mix/laravel-mix/issues/1942 ## 序言 最近在筹划着本博客新主题设计,想运用现代化前端技术,再加之对 Laravel mix 有一定的使用经验,所以选择了 Laravel mix 作为脚手架 ## 问题 `webpack.mix.js` 配置: ```js const mix = require('laravel-mix'); require('mix-tailwindcss'); mix.disableSuccessNotifications() .ts('src/app.ts', 'theme/assets') .setPublicPath('theme/assets') .sass("src/assets/sass/app.scss", "theme/assets") .tailwind('./tailwind.config.js') .webpackConfig({ module: { rules: [ { test: /\.tsx?$/, loader: "ts-loader", exclude: /node_modules/ } ] } }) mix.browserSync({ proxy: '127.0.0.1:3792', files: ["theme/**/*.php", "src/*.js", "src/*.css"], open: false }) ``` `tailwind.config.js` 配置: ```js module.exports = { content: require('fast-glob').sync([ './src/**/*.{html,js,ts}', './node_modules/tw-elements/dist/js/**/*.js', './theme/**/*.php' ]), theme: { extend: {}, }, plugins: [ require('tw-elements/dist/plugin') ], } ``` 使用上述的配置,然后运行 `npm run watch`,就看到终端一直闪烁着编译结果,然后电脑风扇呼呼狂啸:  ## 解决方案 还好我用 Google + 英文搜索(用的蹩脚英文 ?),然后找到了这个 **issues**: https://github.com/laravel-mix/laravel-mix/issues/1942 翻啊翻,发现这个人给出的解决方案是可行的:https://github.com/laravel-mix/laravel-mix/issues/1942#issuecomment-998148038 1. 首先安装 `glob` - npm:`npm install fast-glob -D` - yarn:`yarn add fast-glob -D` 2. 然后将 `tailwind.config.js` 改为: ```js module.exports = { // 看这里 content: require('fast-glob').sync([ './src/**/*.{html,js,ts}', './node_modules/tw-elements/dist/js/**/*.js', './theme/**/*.php' ]), theme: { extend: {}, }, plugins: [], } ``` 然后就完美解决了