Skip to content

Instantly share code, notes, and snippets.

@xiaoysh8
xiaoysh8 / laravel HTTP Basic Authentication
Created June 3, 2018 13:55
laravel HTTP Basic Authentication
HTTP Basic Authentication
@xiaoysh8
xiaoysh8 / git 修改.gitignore后生效
Created June 3, 2018 14:50
git 修改.gitignore后生效
git 修改.gitignore后生效
git rm -r --cached . #清除缓存
git add . #重新trace file
git commit -m "update .gitignore" #提交和注释
git push origin master #可选,如果需要同步到remote上的话
@xiaoysh8
xiaoysh8 / laravel message
Created June 4, 2018 07:19
laravel message
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
{{ csrf_field() }}
@if ($errors->has('cate'))
<span class="invalid-feedback">
<strong>{{ }}</strong>
</span>
@xiaoysh8
xiaoysh8 / linux tar
Created June 5, 2018 07:04
linux tar
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
Here’s what those switches actually mean:
-c: Create an archive.
-z: Compress the archive with gzip.
-v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful.
-f: Allows you to specify the filename of the archive.
tar -czvf archive.tar.gz /home/ubuntu --exclude=/home/ubuntu/Downloads --exclude=/home/ubuntu/.cache
tar -czvf archive.tar.gz /home/ubuntu --exclude=*.mp4
@xiaoysh8
xiaoysh8 / linux group
Last active July 4, 2018 02:30
linux group
//Add an Existing User Account to a Group
usermod -a -G examplegroup exampleusername
usermod -a -G sudo geek
//Change a User’s Primary Group
usermod -g groupname username
@xiaoysh8
xiaoysh8 / laravel factory create
Created July 4, 2018 07:07
laravel factory create
factory(App\User::class, 100)->create()->each(function($u) {
$u->profile()->save(factory(App\Models\Profile::class)->make());
$u->wx()->save(factory(App\Models\Wx::class)->make());
for( $i=0; $i<rand(0, 100); $i++){
$u->stats()->save(factory(App\Models\Stat::class)->make());
}
});
@xiaoysh8
xiaoysh8 / linux tree
Created July 10, 2018 02:23
linux tree
tree -L 2
@xiaoysh8
xiaoysh8 / laravel error message
Created July 10, 2018 04:10
laravel error message
Laravel 手动返回错误码
设想到一个情景,如果新增数据库时用户提交的数据正确,也就是通过了验证,但是添加数据库时发生错误,比如:
if(!$users->save()){
//新增数据库时发生错误
}
那么需要返回错误信息,这个时候怎么手动呢?找到了一个函数,特此记录,感觉够用了:
@xiaoysh8
xiaoysh8 / ajax object message
Created July 17, 2018 02:29
ajax object message
<script>
var _token = '{{csrf_token()}}';
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': _token
}
});
</script>
接下来就可以把错误信息提取出来了。
@xiaoysh8
xiaoysh8 / Laravel Composer Content-Length mismatch
Last active July 20, 2018 05:46
Laravel Composer Content-Length mismatch
composer clear-cache
按照 中文镜像 配置全局镜像:
composer config -g repo.packagist composer https://packagist.laravel-china.org
再次尝试:
composer create-project laravel/laravel Laravel --prefer-dist "5.1.*"