Skip to content

Commit

Permalink
Topic index page
Browse files Browse the repository at this point in the history
  • Loading branch information
vagrant committed Apr 4, 2018
1 parent fe16cd6 commit 4f10743
Show file tree
Hide file tree
Showing 11 changed files with 517 additions and 86 deletions.
70 changes: 35 additions & 35 deletions app/Http/Controllers/TopicsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,52 @@

class TopicsController extends Controller
{
public function __construct()
public function __construct ()
{
$this->middleware('auth', ['except' => ['index', 'show']]);
$this->middleware ( 'auth' , [ 'except' => [ 'index' , 'show' ] ] );
}

public function index()
{
$topics = Topic::paginate();
return view('topics.index', compact('topics'));
}
public function index ()
{
$topics = Topic::with ( 'user' , 'category' )->paginate ( 30 );
return view ( 'topics.index' , compact ( 'topics' ) );
}

public function show(Topic $topic)
public function show ( Topic $topic )
{
return view('topics.show', compact('topic'));
return view ( 'topics.show' , compact ( 'topic' ) );
}

public function create(Topic $topic)
{
return view('topics.create_and_edit', compact('topic'));
}
public function create ( Topic $topic )
{
return view ( 'topics.create_and_edit' , compact ( 'topic' ) );
}

public function store(TopicRequest $request)
{
$topic = Topic::create($request->all());
return redirect()->route('topics.show', $topic->id)->with('message', 'Created successfully.');
}
public function store ( TopicRequest $request )
{
$topic = Topic::create ( $request->all () );
return redirect ()->route ( 'topics.show' , $topic->id )->with ( 'message' , 'Created successfully.' );
}

public function edit(Topic $topic)
{
$this->authorize('update', $topic);
return view('topics.create_and_edit', compact('topic'));
}
public function edit ( Topic $topic )
{
$this->authorize ( 'update' , $topic );
return view ( 'topics.create_and_edit' , compact ( 'topic' ) );
}

public function update(TopicRequest $request, Topic $topic)
{
$this->authorize('update', $topic);
$topic->update($request->all());
public function update ( TopicRequest $request , Topic $topic )
{
$this->authorize ( 'update' , $topic );
$topic->update ( $request->all () );

return redirect()->route('topics.show', $topic->id)->with('message', 'Updated successfully.');
}
return redirect ()->route ( 'topics.show' , $topic->id )->with ( 'message' , 'Updated successfully.' );
}

public function destroy(Topic $topic)
{
$this->authorize('destroy', $topic);
$topic->delete();
public function destroy ( Topic $topic )
{
$this->authorize ( 'destroy' , $topic );
$topic->delete ();

return redirect()->route('topics.index')->with('message', 'Deleted successfully.');
}
return redirect ()->route ( 'topics.index' )->with ( 'message' , 'Deleted successfully.' );
}
}
12 changes: 11 additions & 1 deletion app/Models/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,15 @@

class Topic extends Model
{
protected $fillable = ['title', 'body', 'user_id', 'category_id', 'reply_count', 'view_count', 'last_reply_user_id', 'order', 'excerpt', 'slug'];
protected $fillable = [ 'title' , 'body' , 'user_id' , 'category_id' , 'reply_count' , 'view_count' , 'last_reply_user_id' , 'order' , 'excerpt' , 'slug' ];

public function category ()
{
return $this->belongsTo ( Category::class );
}

public function user ()
{
return $this->belongsTo ( User::class );
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"overtrue/laravel-lang": "~3.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "~3.1",
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "~1.0",
Expand Down
131 changes: 130 additions & 1 deletion composer.lock

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

Loading

0 comments on commit 4f10743

Please sign in to comment.