原创 non-fast-forward

問題前提: 在github上新建project後,提交本地代碼到遠程倉庫時,報以下錯誤: ! [rejected] master -> master (non-fast-forward) error: failed to

原创 laravel Event事件 和事件處理器(事件監聽器)Listeners

概念: 事件是一種常見的觀察者模式的應用。 含義:當 (event)... 然後(幹) (listener)... 業務邏輯處理:事件event除了定義屬性和注入事件參數外不做業務邏輯處理,而是交給事件處理器(即監聽器listener)

原创 laravel unittest測試

約定: 測試文件名需要以 Test 作爲後綴,比如如果要測試 First.php,則對應的測試文件名爲 FirstTest.php; 測試方法名需要以 test 作爲前綴,比如如果要測試的方法名爲 getuser,則對應的測試方法名爲

原创 laravel 訪問器 & 修改器

訪問器作用:在模型中定義某字段的獲取形式。如, /** * 獲取用戶的名字。 * * @param string $value * @return string */ pu

原创 mysql鎖(行鎖,表鎖,頁面鎖)

MySQL常用存儲引擎的鎖機制 MyISAM和MEMORY : 表級鎖(table-level locking) BDB採用頁面鎖(page-level locking)或表級鎖:頁面鎖 InnoDB:表級鎖,默認爲行級鎖 mysq

原创 【shell】練習- read from file

#!/bin/bash # read from file example filename=$1 if [ $filename != "" ];then while read fileline do echo

原创 laravel with方法應用

應用場景:一對多的關聯關係中。 作用:是爲了避免N+1次的查詢數據庫, 從而提升查詢的性能; 分類model <?php namespace App\Models; use Illuminate\Database\Eloquent

原创 laravel 作用域應用

分類爲:分爲全局作用域,和本地作用域。 作用域作用:給模型的查詢都添加上約束。 全局作用域 繼承Illuminate\Database\Eloquent\Scope 接口的類,並實現 apply 方法。 根據需求,在 apply 加

原创 【shell】練習- select

#!/bin/bash # select command example select iterm in apple xiaomi huawei oneplus sansam vovo do echo "你選擇了$iterm"

原创 【shell】練習- 雙中括號-規則匹配

#!/bin/bash # 注意,雙中括號是可以規則匹配 ,而單中括號是 test的簡寫 read -p "please input the number[0~9]: " num if [[ $num =~ [0-9]+ ]] ;t

原创 【shell】練習- 判斷 - 正則

#!/bin/bash # it's a intval while true ;do read -p "請輸入 > " num if [ -z "$num" ];then echo "沒有輸入.." elif [[ "$n

原创 【shell】練習- 腳本參數

#!/bin/sh # first script of shell # practise params echo '腳本'$0 echo '接收到參數個數:'$# echo '所有的參數:' echo $@ j=0 for

原创 【shell】練習- if 判斷

#!/bin/sh read -p "判斷文件存不存在(輸入文件絕對路徑): " file if test -f $file ;then echo it\'s exsit else echo empty fi  

原创 【shell】練習- case

#!/bin/bash # case example OS=$(uname -s) case "$OS" in FreeBSD) echo "This is FreeBSD" ;; Darwin) echo "This is

原创 【shell】練習- while

#!/bin/bash #echo "總共有 $# 個參數" #while [ "$1" != "" ];do # echo -n "剩下 $# 個參數" # echo ", 移除參數:$1" # shift #d