1. 程式人生 > >laravel項目1myPersimmon學習

laravel項目1myPersimmon學習

resp mtime ngs strtotime apple 跳轉 lin ted build

歸類用法

$links = Links::all();

$configs = Options::all(array(‘id‘, ‘option_name‘, ‘option_value‘));

$category = Categorys::where(‘category_flag‘, $flag)->first();

$post = Posts::where(‘flag‘, $flag)->first();

$posts = Posts::OfType(‘post‘)->orderBy(‘id‘, ‘desc‘)->take(15)->get();

$posts = $category->posts()->paginate(15);//關系,這個分類的文章15個,$this->belongsTo(‘Categorys::class’) ,$this->belongsToMany(‘Tags::class’);

$posts = Posts::orderBy(‘id‘, ‘desc‘)->paginate(15);

Posts::increment(‘views‘, 1);

$post->categories;

$post->tags;

$post->user;

$categorys = Categorys::firstOrCreate

([‘category_name‘ => $category]);

特殊函數

$key = hash(‘sha256‘, $flag);

Cache

$post = cache($key);

cache([$key => $post], $this->expiresAt);

Cache::has(‘rss-feed‘)

Cache::add(‘rss-feed‘, $rss, $expiresAt);

return Cache::get(‘rss-feed‘);

}

時間函數

{{$post->created_at->format(‘c‘)}

$this->expiresAt = Carbon::now()->addMinutes(1440);

$expiresAt = Carbon::createFromTimestamp(strtotime($options->updated_at))->addMinutes(10);//獲取距離當前時間函數

$ts = Carbon::yesterday()->timestamp;

//人性化顯示時間

echo Carbon::createFromTimestamp($ts)->diffForHumans();

上面的打印結果是1天前

Carbon::createFromTimestamp(strtotime($date))->addDays(30);

carbon->toDateString() <= date(‘Y-m-d‘)

跳轉函數

<a href="{{ route(‘tags‘,[$tag->tags_flag]) }}"

->url(url(‘/‘)) //裏面放的是路由值

->url(url(‘/post/‘ . $post->flag))

$data[‘link‘] = route(‘posts‘, [$post->wp_slug]);//名字

響應

return response($rss)->header(‘Content-type‘, ‘text/xml; charset=UTF-8‘);

return response($map)->header(‘Content-type‘, ‘text/xml‘);

return response()->json($lists);

2 build做方法名稱不錯

buildRssData

public function authenticate($email, $password)//認證

laravel項目1myPersimmon學習