laravel项目1myPersimmon学习
Posted 克维拉
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel项目1myPersimmon学习相关的知识,希望对你有一定的参考价值。
归类用法
查
$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学习的主要内容,如果未能解决你的问题,请参考以下文章
php Usar la clase Db en Laravel para hacer consultas a la base de datos
markdown Para definir布局de la forma tradicional con Blade en Laravel usamos la directiva @yield de es