Skip to content

Commit

Permalink
0822
Browse files Browse the repository at this point in the history
  • Loading branch information
osramywj committed Aug 22, 2017
1 parent 73dd296 commit f052757
Show file tree
Hide file tree
Showing 2,142 changed files with 571,334 additions and 25 deletions.
13 changes: 13 additions & 0 deletions app/Admin/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Admin\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
24 changes: 24 additions & 0 deletions app/Admin/Controllers/LoginController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace App\Admin\Controllers;

use App\Http\Requests\Request;

class LoginController extends Controller
{
//登录页面
public function index()
{
return view('admin.login.index');
}

//登录操作
public function login(Request $request)
{
$this->validate($request,[
'email' =>'required|email',
'password' =>'required|min:3|max:10',
'is_remember' =>'integer'
]);
return ;
}
}
1 change: 0 additions & 1 deletion app/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function login(Request $request)
$this->validate($request,[
'email' =>'required|email',
'password' =>'required|min:3|max:10',
'is_remember' =>'integer'
]);
//
// //逻辑
Expand Down
29 changes: 25 additions & 4 deletions app/Http/Controllers/TopicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,39 @@
namespace App\Http\Controllers;

use App\Post;
use App\PostTopic;
use App\Topic;
use Illuminate\Http\Request;

class TopicController extends Controller
{
public function show()
public function show(Topic $topic)
{
return view('topic.show');
//该专题下的所有文章
$topic = Topic::find($topic->id);
$posts = $topic->post;

// $post_topics = PostTopic::where('topic_id',$topic->id)->get();
// foreach ($post_topics as $key=>$post_topic) {
// $posts[$key] = $post_topic->post;
// }
//当前作者不在该专题内的所有文章
// $postNotInTopic = Post::postOfUser($topic->id)->get();
$postNotInTopic = Post::postNotMine($topic->id)->get();
return view('topic.show',compact('topic','posts','postNotInTopic'));
}

public function submit(Post $post)
public function submit(Request $request,Topic $topic)
{
return ;
$this->validate($request,[
'post_ids'=>'required|array'
]);
$topic_id = $topic->id;
$post_ids = $request->input('post_ids');
foreach ($post_ids as $post_id) {
$data=compact('topic_id','post_id');
PostTopic::create($data);
}
return back();
}
}
32 changes: 32 additions & 0 deletions app/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;

class Post extends Model
{
Expand All @@ -27,4 +28,35 @@ public function zan($user_id)
{
return $this->hasOne('App\Zan')->where('user_id',$user_id);
}




// //当前登录用户的所有不属于某个专题的文章
// public function scopePostOfUser(\Illuminate\Database\Eloquent\Builder $query,$topic_id)
// {
// return $query->where('user_id',\Auth::id())->doesntHave('PostTopic','and', function ($q) use($topic_id) {
// $q->where('topic_id',$topic_id);
// });
// }
//
// //文章对应的专题 一对一
// public function PostTopic()
// {
// return $this->belongsTo('App\PostTopic','id','post_id');
// }

public function topic()
{
return $this->belongsToMany('App\Topic','post_topics','post_id','topic_id');
}

//当前登录用户的所有不属于某个专题的文章
public function scopePostNotMine(\Illuminate\Database\Eloquent\Builder $query,$topic_id)
{
return $query->where('user_id',\Auth::id())->doesntHave('topic','and', function ($q) use($topic_id) {
$q->where('topic_id',$topic_id);
});
}

}
6 changes: 6 additions & 0 deletions app/PostTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
class PostTopic extends Model
{
protected $guarded = [];

public function post()
{
return $this->hasOne('App\Post','id','post_id');
}

}
10 changes: 10 additions & 0 deletions app/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@
class Topic extends Model
{
protected $guarded = [];

public function postTopic()
{
return $this->hasMany('App\PostTopic','topic_id','id');
}

public function post()
{
return $this->belongsToMany('App\Post','post_topics','topic_id','post_id');
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "^1.0"
"laravel/tinker": "^1.0",
"almasaeed2010/adminlte": "~2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down
42 changes: 41 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions public/adminlte/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.DS_Store
*.log
*.zip
.idea
.sass-cache/
/nbproject/
/nbproject/private/
/node_modules/
/bower_components/
ad.js
TODO
test.html
17 changes: 17 additions & 0 deletions public/adminlte/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"asi" : true,
"browser" : true,
"eqeqeq" : false,
"eqnull" : true,
"es3" : true,
"expr" : true,
"jquery" : true,
"latedef" : "nofunc",
"laxbreak" : true,
"nonbsp" : true,
"strict" : true,
"undef" : true,
"unused" : true,
// External variabls and plugins
"predef": [ "AdminLTEOptions", "FastClick", "moment", "Morris", "Chart" ]
}
Loading

0 comments on commit f052757

Please sign in to comment.