Skip to content

Commit 41da510

Browse files
authored
Merge pull request #6 from jsalzano92/posts
Posts and beginning of comments merged
2 parents d5d1eb3 + dd7e347 commit 41da510

File tree

13 files changed

+195
-10
lines changed

13 files changed

+195
-10
lines changed

app/Comment.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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->belongsTo('SoftwareHerd\Comment');
12+
}
13+
14+
public function user()
15+
{
16+
return $this->belongsTo('SoftwareHerd\User');
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace SoftwareHerd\Http\Controllers;
3+
4+
use SoftwareHerd\Post;
5+
use Illuminate\Http\Request;
6+
7+
class CommentController extends Controller
8+
{
9+
public function projectCreateComment(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+
}
18+
}

app/Http/Controllers/PostController.php

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

7-
class ProjectController extends Controller
7+
class PostController extends Controller
88
{
9+
public function projectCreatePost(request $request)
10+
{
11+
$post = new Post();
12+
$post->title = $request['title'];
13+
$post->info = $request['info'];
14+
$post->posting_project = $request->project()->id;
15+
save($post);
16+
return view('home');
17+
}
918

10-
11-
12-
13-
19+
public function post($id) {
20+
$post = Post::find($id);
21+
return view('news_post', array('post' => $post));
22+
}
1423
}

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->belongsTo('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
}

app/User.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ public function projects()
1313
{
1414
return $this->hasMany('SoftwareHerd\Project');
1515
}
16-
16+
17+
public function comments()
18+
{
19+
return $this->hasMany('SoftwareHerd\Comment');
20+
}
1721

1822
/**
1923
* The attributes that are mass assignable.
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: 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 AddSummaryPosts 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->string('summary', 255)->nullable();
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('summary');
30+
});
31+
}
32+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@foreach ($project->posts->sortByDesc('created_at') as $post)
2+
<a href="../news_post/{{$post->id}}">{{ $post->title }}</a><br>
3+
{{$post->created_at}}<br>
4+
{{$post->summary}}</br><br>
5+
@endforeach

0 commit comments

Comments
 (0)