public function store() {
Article::create(Request::all());
return redirect('articles');
}
@extends('layout')
@section('content')
<h1>Write a New Article</h1>
<hr/>
{{--使用我们添加的 illuminate\html 开源库--}}
{!! Form::open(['url' => 'articles']) !!}
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('body', 'Body:') !!}
{!! Form::textarea('body', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('published_at', 'Publish On:') !!}
{!! Form::input('date', 'published_at', date('Y-m-d'), ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Add Article', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
@stop
<?php namespace App;
use DateTime;
use Illuminate\Database\Eloquent\Model;
class Article extends Model {
protected $fillable = [
'title',
'body',
'published_at'
];
//属性设置其要遵守格式约定
// set属性Attribute
public function setPublishedAtAttribute($date) {
$this->attributes['published_at'] = Carbon::createFromFormat('Y-m-d', $date)->hour(8)->minute(0)->second(0);
}
}
public function index() {
//$articles = Article::latest('published_at')->get();
$articles = Article::latest('published_at')->where('published_at', '<=', Carbon::now())->get();
return view('articles.index', compact('articles'));
}
//设置scope,遵守命名规则
public function scopePublished($query) {
$query->where('published_at', '<=', Carbon::now());
}
public function index() {
//$articles = Article::latest('published_at')->get();
//$articles = Article::latest('published_at')->where('published_at', '<=', Carbon::now())->get();
$articles = Article::latest('published_at')->published()->get();
return view('articles.index', compact('articles'));
}
public function scopeUnpublished($query) {
$query->where('published_at', '>', Carbon::now());
}
public function index() {
//$articles = Article::latest('published_at')->get();
//$articles = Article::latest('published_at')->where('published_at', '<=', Carbon::now())->get();
//$articles = Article::latest('published_at')->published()->get();
$articles = Article::latest('published_at')->Unpublished()->get();
return view('articles.index', compact('articles'));
}
protected $dates = ['published_at'];
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有