Skip to content

Commit b78ef19

Browse files
author
Joseph Salzano
committed
Groundwork for posts/comments system.
1 parent d5d1eb3 commit b78ef19

File tree

10 files changed

+134
-8
lines changed

10 files changed

+134
-8
lines changed

app/Comment.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace SoftwareHerd;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Comment extends Model
8+
{
9+
public function post()
10+
{
11+
return $this->belongs_to('SoftwareHerd\Comment');
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
namespace SoftwareHerd\Http\Controllers;
3+
4+
use SoftwareHerd\Post;
5+
use Illuminate\Http\Request;
6+
7+
class PostController extends Controller
8+
{
9+
public function projectCreatePost(request $request)
10+
{
11+
$post = new Post();
12+
$post->title = $request['title'];
13+
$post->description = $request['description'];
14+
$post->posting_project = $request->project()->id;
15+
//$request->projects()->-posts->save($post);
16+
return view('home');
17+
}
18+
19+
public function post($id) {
20+
$post = Post::find($id);
21+
return view('news_post', array('post' => $post));
22+
}
23+
}

app/Http/Controllers/PostController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
use SoftwareHerd\Post;
55
use Illuminate\Http\Request;
66

7-
class ProjectController extends Controller
7+
class CommentController extends Controller
88
{
9-
10-
11-
12-
13-
9+
public function projectCommentPost(request $request)
10+
{
11+
$comment = new Comment();
12+
$comment->title = $request['title'];
13+
$comment->description = $request['description'];
14+
$comment->posting_project = $request->project()->id;
15+
//$request->projects()->posts->save($post);
16+
return view('home');
17+
}
1418
}

app/Post.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@
66

77
class Post extends Model
88
{
9-
//
10-
}
9+
public function project()
10+
{
11+
return $this->belongs_to('SoftwareHerd/Project','posting_project');
12+
}
13+
14+
public function comments()
15+
{
16+
return $this->hasMany('SoftwareHerd\Comment');
17+
}
18+
}

app/Project.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ public function user()
1212
{
1313
return $this->belongsTo('SoftwareHerd\User');
1414
}
15+
16+
public function posts()
17+
{
18+
return $this->hasMany('SoftwareHerd\Post', 'posting_project')->orderBy('created_at', 'desc');
19+
}
1520
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class UpdatePostsDb extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('posts', function (Blueprint $table) {
17+
$table->integer('posting_project');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('posts', function (Blueprint $table) {
29+
$table->dropColumn('posting_project');
30+
});
31+
}
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateCommentsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('comments', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->timestamps();
19+
$table->text('data');
20+
$table->integer('post_id');
21+
$table->integer('user_id');
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function down()
31+
{
32+
Schema::dropIfExists('comments');
33+
}
34+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@foreach ($project->posts->sortByDesc('created_at') as $post)
2+
@include('news_post')
3+
@endforeach
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{$post->title}}<br>
2+
<?php echo $post->info; ?>

resources/views/project.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
<h4><a href="/members/{{ $project->id }}">Members</a></h4>
2828

29+
@include('news_list')
30+
2931
<div>
3032
</div>
3133

0 commit comments

Comments
 (0)