Skip to content
This repository was archived by the owner on Aug 1, 2020. It is now read-only.

Database Migration #2

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.phpstorm.meta.php
.DS.Store
_ide_helper.php
/vendor
/node_modules
/public/storage
Expand All @@ -10,4 +13,4 @@ Homestead.json
/material-foundation/.sass-cache
.phpstorm.meta.php
_ide_helper.php
/public/build
/public/build
2 changes: 1 addition & 1 deletion .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/**
* PhpStorm Meta file, to provide autocomplete information for PhpStorm
* Generated on 2016-07-27.
* Generated on 2016-10-03.
*
* @author Barry vd. Heuvel <[email protected]>
* @see https://github.com/barryvdh/laravel-ide-helper
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# NoticeBoard
# NoticeBoard

Rebuild with laravel
77 changes: 58 additions & 19 deletions _ide_helper.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* A helper file for Laravel 5, to provide autocomplete information to your IDE
* Generated for Laravel 5.2.41 on 2016-07-27.
* Generated for Laravel 5.2.41 on 2016-10-03.
*
* @author Barry vd. Heuvel <[email protected]>
* @see https://github.com/barryvdh/laravel-ide-helper
Expand Down Expand Up @@ -1627,17 +1627,6 @@ public static function viaRemember(){
return \Illuminate\Auth\SessionGuard::viaRemember();
}

/**
* Determine if the current user is authenticated.
*
* @return \App\User
* @throws \Illuminate\Auth\AuthenticationException
* @static
*/
public static function authenticate(){
return \Illuminate\Auth\SessionGuard::authenticate();
}

/**
* Determine if the current user is authenticated.
*
Expand All @@ -1658,6 +1647,17 @@ public static function guest(){
return \Illuminate\Auth\SessionGuard::guest();
}

/**
* Determine if the current user is authenticated.
*
* @return \App\User
* @throws \Illuminate\Auth\AuthenticationException
* @static
*/
public static function authenticate(){
return \Illuminate\Auth\SessionGuard::authenticate();
}

}


Expand Down Expand Up @@ -3876,7 +3876,7 @@ public static function applyScopes(){
/**
* Get the underlying query builder instance.
*
* @return \Illuminate\Database\Query\Builder|static
* @return \Illuminate\Database\Query\Builder
* @static
*/
public static function getQuery(){
Expand Down Expand Up @@ -4461,6 +4461,33 @@ public static function orWhereDate($column, $operator, $value){
return \Illuminate\Database\Query\Builder::orWhereDate($column, $operator, $value);
}

/**
* Add a "where time" statement to the query.
*
* @param string $column
* @param string $operator
* @param int $value
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @static
*/
public static function whereTime($column, $operator, $value, $boolean = 'and'){
return \Illuminate\Database\Query\Builder::whereTime($column, $operator, $value, $boolean);
}

/**
* Add an "or where time" statement to the query.
*
* @param string $column
* @param string $operator
* @param int $value
* @return \Illuminate\Database\Query\Builder|static
* @static
*/
public static function orWhereTime($column, $operator, $value){
return \Illuminate\Database\Query\Builder::orWhereTime($column, $operator, $value);
}

/**
* Add a "where day" statement to the query.
*
Expand Down Expand Up @@ -4816,7 +4843,7 @@ public static function count($columns = '*'){
* Retrieve the minimum value of a given column.
*
* @param string $column
* @return float|int
* @return mixed
* @static
*/
public static function min($column){
Expand All @@ -4827,7 +4854,7 @@ public static function min($column){
* Retrieve the maximum value of a given column.
*
* @param string $column
* @return float|int
* @return mixed
* @static
*/
public static function max($column){
Expand All @@ -4838,7 +4865,7 @@ public static function max($column){
* Retrieve the sum of the values of a given column.
*
* @param string $column
* @return float|int
* @return mixed
* @static
*/
public static function sum($column){
Expand All @@ -4849,7 +4876,7 @@ public static function sum($column){
* Retrieve the average of the values of a given column.
*
* @param string $column
* @return float|int
* @return mixed
* @static
*/
public static function avg($column){
Expand All @@ -4860,7 +4887,7 @@ public static function avg($column){
* Alias for the "avg" method.
*
* @param string $column
* @return float|int
* @return mixed
* @static
*/
public static function average($column){
Expand All @@ -4872,13 +4899,25 @@ public static function average($column){
*
* @param string $function
* @param array $columns
* @return float|int
* @return mixed
* @static
*/
public static function aggregate($function, $columns = array()){
return \Illuminate\Database\Query\Builder::aggregate($function, $columns);
}

/**
* Execute a numeric aggregate function on the database.
*
* @param string $function
* @param array $columns
* @return float|int
* @static
*/
public static function numericAggregate($function, $columns = array()){
return \Illuminate\Database\Query\Builder::numericAggregate($function, $columns);
}

/**
* Insert a new record into the database.
*
Expand Down
14 changes: 14 additions & 0 deletions app/Club.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Club extends Model
{
//
public function users()
{
return $this->belongsToMany('App\User');
}
}
21 changes: 21 additions & 0 deletions app/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
protected $fillable = ['content', 'post_id', 'club_post_type', 'tags', 'title'];
//
public function post()
{
return $this->belongsTo('App\Post', 'id');
}

public function author()
{
return $this->belongsTo('App\User', 'user_id', 'id');
}

}
6 changes: 4 additions & 2 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Http\Requests;
use App\Post;
use Illuminate\Http\Request;

class HomeController extends Controller
Expand All @@ -14,7 +15,7 @@ class HomeController extends Controller
*/
public function __construct()
{
$this->middleware('auth');

}

/**
Expand All @@ -24,6 +25,7 @@ public function __construct()
*/
public function index()
{
return view('home');
$posts = Post::with('hasManyComments','tagged')->orderBy('updated_at', 'desc')->get();
return view('welcome')->withPosts($posts);
}
}
78 changes: 78 additions & 0 deletions app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;

use App\Post;
use App\Comment;

class PostController extends Controller
{


//
public function showIndividualPost($id){
if (!Auth::check() && Post::where('id', $id)->value('is_login') == 1) {
return view('login_required')->withErrors('本主题需要登录后查看');
}
return view('post/show')->withPost(Post::with('hasManyComments','tagged')->find($id));
}

public function getReply(Request $request){

if ($user = $request->user()) {
if (!$request->has('content')) {
return redirect()->back()->withInput()->withErrors('评论为空!');
}
if ($comment = new Comment()) {
$comment->user_id = $user->id;
$comment->content = $request->content;
$comment->post_id = $request->post_id;
if (!$comment->save()) {
return redirect()->back()->withInput()->withErrors('评论发表失败!');
}
$post = Post::where('id', $request->post_id)->first();
$post->last_user = $user->id;
if (!$post->save()) {
return redirect()->back()->withInput()->withErrors('更新状态失败!');
}
return redirect()->back();
} else {
return view('login_required')->withErrors('回复需要登录');
}
}
}

public function createSite(){
return view('post/create');
}

public function createNewPost(Request $request)
{
if ($user = $request->user()){
if (!$request->has('content')){
return redirect()->back()->withInput()->withErrors('内容为空!');
}
if ($post = new Post()){
$post->user_id = $user->id;
$post->content = $request->content;
$post->title = $request->title;
$post->save(); // tags need post id !
$post->tag($request->tags);
if ($post->save()) {
return redirect()->back();
} else {
$post->delete(); // 防止错误
}
}
} else {
return view('login_required')->withErrors('发表需要登录');
}
return redirect()->back()->withInput()->withErrors('帖子发表失败!');

}

}
30 changes: 26 additions & 4 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,32 @@
|
*/

Route::get('/', function () {
return view('welcome');
});
Route::get('/', 'HomeController@index');


// 认证路由...
Route::auth();
Route::get('/logout', 'Auth\AuthController@getLogout');

// 注册路由...
Route::get('/register', 'Auth\AuthController@getRegister');
Route::post('/register', 'Auth\AuthController@postRegister');

//帖子...
Route::get('/post/{id}', 'PostController@showIndividualPost');
Route::post('comment', 'PostController@getReply');
Route::post('/post', 'PostController@createNewPost');
Route::get('/post', 'PostController@createSite');

//功能划分
Route::get('/more', 'SectionController@showAllSections');
Route::get('/more/{function}', 'SectionController@showSpecificFunction');
Route::post('/more/{function}', 'SectionController@runSpecificFunction');

//个人中心
Route::get('/profile', 'UserController@showMyself');
Route::get('/profile/{nickname}', 'UserController@showSpecificProfile');

Route::get('/home', 'HomeController@index');
//社区
Route::get('/clubs', 'ClubController@showAllClubs');
Route::get('/clubs/{clubname}', 'ClubController@showSpecificClub');
28 changes: 28 additions & 0 deletions app/Policies/PostPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Policies;

use App\User;
use App\Post;

use Illuminate\Auth\Access\HandlesAuthorization;

class PostPolicy
{
use HandlesAuthorization;

/**
* Create a new policy instance.
*
* @return void
*/
public function __construct()
{
//
}

public function update(User $user, Post $post)
{
return $user->id === $post->user_id;
}
}
Loading