# laravel
數(shù)據(jù)庫顯示最新的數(shù)據(jù)套耕,并排到最上面
latest()->get();
示例:$articles = Article::latest()->get();
跳轉(zhuǎn)到指定路由
return redirect('articles');
獲取post接受過來的數(shù)據(jù)
$request->get('title');
//出現(xiàn)以下錯解決
FatalErrorException in Article.php line 14:
Call to undefined method Carbon\Carbon::createFormFormat()
把
$this->attributes['published_at']=Carbon::createFromFormat('Y-m-d',$date);
修改為:
$this->attributes['published_at']=Carbon::createFromFormat('Y-m-d G:i:s',$date);
就解決了問題谁帕。
為什么會出現(xiàn)這個問題:
input表單的格式和Carbon處理的格式不一樣
Carbon中的diffForHumans()
顯示為1 year ago
類似github項目更新時間
設(shè)置$dates=['published_at']
laravel會把默認(rèn)的published_at
當(dāng)做Carbon對象處理
laravel artisan命令幫助
#查看創(chuàng)建控制器的幫助命令
php artisan help make:controller
laravel 暫時關(guān)閉 CSRF 驗證
在項目目錄
app\Http\Middleware\VerifyCsrfToken.php
class VerifyCsrfToken extends BaseVerifier{
protected $except = [
// 在這里添加不驗證CSRF的url
];
laravel 魔板變量輸出,從1開始
foreach($date as $k=> $result)
//$k為數(shù)組索引
laravel put delete請求
在blade模板中添加
<input type="hidden" name="_method" value="PUT(PATCH冯袍、DELETE)">
資源控制器路由和對應(yīng)表
https://laravel-china.org/docs/5.2/controllers
laravel migrate
執(zhí)行 php artisan migrate --pretend
可以看到migration 建表語句
git 創(chuàng)建git本地倉庫時匈挖,如果不想把某些文件提交到遠(yuǎn)程git倉庫
在本地倉庫根目錄 創(chuàng)建.gitignore文件
vim .gitignore
.env
/vendor
/public/storage
.idea
mysql binlog日志導(dǎo)出為sql文件查看
mysqlbinlog -d 數(shù)據(jù)庫名 binlog文件目錄位置\mysql-bin.00001 > binlog.sql