chore: remove example project code in src-php
This commit is contained in:
parent
26383aa79d
commit
cf8ba61943
|
|
@ -12,32 +12,8 @@ use Validator;
|
||||||
|
|
||||||
class CommentController extends Controller
|
class CommentController extends Controller
|
||||||
{
|
{
|
||||||
public function create(CommentRequest $request)
|
function index()
|
||||||
{
|
{
|
||||||
$input_comment = $request->input('comment');
|
// index
|
||||||
$post = Post::where('hash', $input_comment['post_hash'])->first();
|
}
|
||||||
$input_comment['user_id'] = Auth::id();
|
|
||||||
$input_comment['post_id'] = $post->id;
|
|
||||||
|
|
||||||
if (\session('edit_post_id') === $post->id) {
|
|
||||||
Comment::create($input_comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->back();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(CommentRequest $request)
|
|
||||||
{
|
|
||||||
$input_comment = $request->input('comment');
|
|
||||||
$comment_id = (int)$request->comment_id;
|
|
||||||
$post = Post::where('hash', $input_comment['post_hash'])->first();
|
|
||||||
|
|
||||||
if (\session('edit_post_id') === $post->id) {
|
|
||||||
$comment = Auth::user()->comments()->find($comment_id);
|
|
||||||
$comment->fill($input_comment);
|
|
||||||
$comment->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->back();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,74 +11,8 @@ use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class PostController extends Controller
|
class PostController extends Controller
|
||||||
{
|
{
|
||||||
const CREATE_POST_FLAG = -1;
|
|
||||||
const PAGINATE_NUMBER = 12;
|
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$posts = Post::with('pictures')->orderBy('created_at', 'asc')->paginate(self::PAGINATE_NUMBER);
|
// index
|
||||||
$categories = Category::orderBy('id')->get();
|
|
||||||
return view('home.index', compact('posts', 'categories'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function edit(Request $request, Post $post = null)
|
|
||||||
{
|
|
||||||
$edit_post_id = self::CREATE_POST_FLAG;
|
|
||||||
if ($post === null) {
|
|
||||||
$post = new Post;
|
|
||||||
} else {
|
|
||||||
$edit_post_id = $post->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$request->session()->flash('edit_post_id', $edit_post_id);
|
|
||||||
|
|
||||||
$categories = Category::orderBy('id')->get();
|
|
||||||
return view('admin.post.edit', compact('post', 'categories'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create(PostRequest $request)
|
|
||||||
{
|
|
||||||
$input_post = $request->input('post');
|
|
||||||
$input_post['published_at'] = date_format(new \DateTime(), 'Y-m-d H:i:s');
|
|
||||||
$input_post['user_id'] = Auth::id();
|
|
||||||
|
|
||||||
if (\session('edit_post_id') === self::CREATE_POST_FLAG) {
|
|
||||||
$hashids = new Hashids(config('APP_KEY'), Post::HASH_LEN);
|
|
||||||
$post = Post::create($input_post);
|
|
||||||
$post->hash = $hashids->encode($post->id);
|
|
||||||
$post->save();
|
|
||||||
$request->session()->flash('edit_post_id', self::CREATE_POST_FLAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->route('admin.index');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(PostRequest $request, Post $post)
|
|
||||||
{
|
|
||||||
$input_post = $request->input('post');
|
|
||||||
$input_post['published_at'] = date_format(new \DateTime(), 'Y-m-d H:i:s');
|
|
||||||
$input_post['user_id'] = Auth::id();
|
|
||||||
|
|
||||||
if (\session('edit_post_id') === $post->id) {
|
|
||||||
$post->fill($input_post);
|
|
||||||
$post->save();
|
|
||||||
$request->session()->flash('edit_post_id', self::CREATE_POST_FLAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->route('admin.index');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show(Request $request, Post $post)
|
|
||||||
{
|
|
||||||
$request->session()->flash('edit_post_id', $post->id);
|
|
||||||
|
|
||||||
return view('home.detail', compact('post'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete(Post $post)
|
|
||||||
{
|
|
||||||
$post and $post->delete();
|
|
||||||
return redirect()->route('admin.index');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,32 +8,8 @@ use App\Rules\Category;
|
||||||
|
|
||||||
class PostRequest extends FormRequest
|
class PostRequest extends FormRequest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
if ($this->path !== 'post') {
|
// authorize
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
// 'post.category_id' => new Category,
|
|
||||||
'post.thumb' => 'between:1,255',
|
|
||||||
'post.title' => 'between:0,255',
|
|
||||||
'post.content' => 'between:0,8191'
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,6 @@ class Category extends Model
|
||||||
{
|
{
|
||||||
public function posts()
|
public function posts()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Post');
|
// posts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Post extends Model
|
class Post extends Model
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'user_id', 'title', 'thumb', 'content', 'published_at', 'category_id'
|
|
||||||
];
|
|
||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\User');
|
// user
|
||||||
}
|
|
||||||
|
|
||||||
public function comments()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Comment');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function category()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Category');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function pictures()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Picture');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue