diff --git a/app/Http/Controllers/TopicsController.php b/app/Http/Controllers/TopicsController.php new file mode 100644 index 0000000..f7cb3e1 --- /dev/null +++ b/app/Http/Controllers/TopicsController.php @@ -0,0 +1,58 @@ +middleware('auth', ['except' => ['index', 'show']]); + } + + public function index() + { + $topics = Topic::paginate(); + return view('topics.index', compact('topics')); + } + + public function show(Topic $topic) + { + return view('topics.show', 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 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()); + + return redirect()->route('topics.show', $topic->id)->with('message', 'Updated successfully.'); + } + + public function destroy(Topic $topic) + { + $this->authorize('destroy', $topic); + $topic->delete(); + + return redirect()->route('topics.index')->with('message', 'Deleted successfully.'); + } +} \ No newline at end of file diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php new file mode 100644 index 0000000..4980076 --- /dev/null +++ b/app/Http/Requests/Request.php @@ -0,0 +1,14 @@ +method()) { + // CREATE + case 'POST': + { + return [ + // CREATE ROLES + ]; + } + // UPDATE + case 'PUT': + case 'PATCH': + { + return [ + // UPDATE ROLES + ]; + } + case 'GET': + case 'DELETE': + default: + { + return []; + }; + } + } + + public function messages() + { + return [ + // Validation messages + ]; + } +} diff --git a/app/Models/Model.php b/app/Models/Model.php new file mode 100644 index 0000000..1a7eb54 --- /dev/null +++ b/app/Models/Model.php @@ -0,0 +1,19 @@ +orderBy('id', 'desc'); + } + + public function scopeOrdered($query) + { + return $query->orderBy('order', 'desc'); + } + +} diff --git a/app/Models/Topic.php b/app/Models/Topic.php new file mode 100644 index 0000000..7e9d8c6 --- /dev/null +++ b/app/Models/Topic.php @@ -0,0 +1,8 @@ +isSuperAdmin()) { + // return true; + // } + } +} diff --git a/app/Policies/TopicPolicy.php b/app/Policies/TopicPolicy.php new file mode 100644 index 0000000..2a95543 --- /dev/null +++ b/app/Policies/TopicPolicy.php @@ -0,0 +1,20 @@ +user_id == $user->id; + return true; + } + + public function destroy(User $user, Topic $topic) + { + return true; + } +} diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 687c65c..5c148bb 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -14,6 +14,7 @@ class AuthServiceProvider extends ServiceProvider * @var array */ protected $policies = [ + \App\Models\Topic::class => \App\Policies\TopicPolicy::class, 'App\Model' => 'App\Policies\ModelPolicy', User::class => UserPolicy::class, ]; diff --git a/database/factories/TopicFactory.php b/database/factories/TopicFactory.php new file mode 100644 index 0000000..25f3e9a --- /dev/null +++ b/database/factories/TopicFactory.php @@ -0,0 +1,9 @@ +define(App\Models\Topic::class, function (Faker $faker) { + return [ + // 'name' => $faker->name, + ]; +}); diff --git a/database/migrations/2017_12_31_131710_create_topics_table.php b/database/migrations/2017_12_31_131710_create_topics_table.php new file mode 100644 index 0000000..1217347 --- /dev/null +++ b/database/migrations/2017_12_31_131710_create_topics_table.php @@ -0,0 +1,30 @@ +increments('id'); + $table->string('"title')->index(); + $table->text('body'); + $table->integer('user_id')->unsigned()->index(); + $table->integer('category_id')->unsigned()->index(); + $table->integer('reply_count')->unsigned()->default(0); + $table->integer('view_count')->unsigned()->default(0); + $table->integer('last_reply_user_id')->unsigned()->default(0); + $table->integer('order')->unsigned()->default(0); + $table->text('excerpt'); + $table->string('slug')->nullable(); + $table->timestamps(); + }); + } + + public function down() + { + Schema::drop('topics'); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index e119db6..cacec49 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -12,5 +12,6 @@ class DatabaseSeeder extends Seeder public function run() { // $this->call(UsersTableSeeder::class); + $this->call(TopicsTableSeeder::class); } } diff --git a/database/seeds/TopicsTableSeeder.php b/database/seeds/TopicsTableSeeder.php new file mode 100644 index 0000000..8588842 --- /dev/null +++ b/database/seeds/TopicsTableSeeder.php @@ -0,0 +1,20 @@ +times(50)->make()->each(function ($topic, $index) { + if ($index == 0) { + // $topic->field = 'value'; + } + }); + + Topic::insert($topics->toArray()); + } + +} + diff --git a/resources/views/common/error.blade.php b/resources/views/common/error.blade.php new file mode 100644 index 0000000..166b234 --- /dev/null +++ b/resources/views/common/error.blade.php @@ -0,0 +1,10 @@ +@if (count($errors) > 0) +
There were some problems with your input.
+# | +"title | +Body | +User_id | +Category_id | +Reply_count | +View_count | +Last_reply_user_id | +Order | +Excerpt | +Slug | +OPTIONS | +
---|---|---|---|---|---|---|---|---|---|---|---|
{{$topic->id}} | + +{{$topic->title}} | +{{$topic->body}} | +{{$topic->user_id}} | +{{$topic->category_id}} | +{{$topic->reply_count}} | +{{$topic->view_count}} | +{{$topic->last_reply_user_id}} | +{{$topic->order}} | +{{$topic->excerpt}} | +{{$topic->slug}} | + ++ + + + + + + + + + | +
+ {{ $topic->title }} +
++ {{ $topic->body }} +
++ {{ $topic->user_id }} +
++ {{ $topic->category_id }} +
++ {{ $topic->reply_count }} +
++ {{ $topic->view_count }} +
++ {{ $topic->last_reply_user_id }} +
++ {{ $topic->order }} +
++ {{ $topic->excerpt }} +
++ {{ $topic->slug }} +
+