Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group discussion board #99

Merged
merged 38 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ebe8cc5
Created the initial page and routes for group discussions
WillTheDeveloper May 28, 2022
599731e
Corrected the formatting
WillTheDeveloper May 28, 2022
0ef7c0b
Created migrations and models
WillTheDeveloper May 28, 2022
87529a0
Added the relationships
WillTheDeveloper May 28, 2022
50ac282
Added data from DB to discussions
WillTheDeveloper May 28, 2022
d501245
Added reply list
WillTheDeveloper May 28, 2022
d3c5971
Added some more stuff to group discussion page
WillTheDeveloper May 30, 2022
f94d92c
Fixed dashboard minor issue
WillTheDeveloper Jun 1, 2022
017bd9f
Added dropdown js
WillTheDeveloper Jun 1, 2022
32b8bf9
Added lock,unlock,delete functionality to discussions
WillTheDeveloper Jun 1, 2022
fa038eb
Delete replies alongside the discussion
WillTheDeveloper Jun 1, 2022
699dfcf
Designed the discussions page
WillTheDeveloper Jun 1, 2022
8e8ddb7
Content is shown correct on discussion replies
WillTheDeveloper Jun 1, 2022
58380e4
Added user links to discussion reply pages
WillTheDeveloper Jun 1, 2022
f3e9ef8
Closed all div tags
WillTheDeveloper Jun 1, 2022
6d588d8
Fixed layout issues
WillTheDeveloper Jun 5, 2022
221b0bd
wip creating replies
WillTheDeveloper Jun 5, 2022
c926927
Added fillable to replies
WillTheDeveloper Jun 5, 2022
9c65bf3
Added js for dropdowns on discussions chat page
WillTheDeveloper Jun 5, 2022
992a7de
Added locked status for chats on discussions
WillTheDeveloper Jun 5, 2022
aedbb91
Made the main response prettier
WillTheDeveloper Jun 5, 2022
29bd1ff
changed comment to reply
WillTheDeveloper Jun 5, 2022
012b626
wip reply
WillTheDeveloper Jun 5, 2022
be7cef3
Maybe wip replies
WillTheDeveloper Jun 6, 2022
41691e9
Replies working
WillTheDeveloper Jun 6, 2022
5743af8
fixed query issue
WillTheDeveloper Jun 6, 2022
5cd8c06
adjusted redirect route for deleting discussions
WillTheDeveloper Jun 6, 2022
ec7f08d
Hidden the replies on discussions page
WillTheDeveloper Jun 6, 2022
6094268
Updated the name of some tests on students
WillTheDeveloper Jun 6, 2022
6fdeabc
Replies borked
WillTheDeveloper Jun 7, 2022
ba1a9a7
Updated packages
WillTheDeveloper Jun 20, 2022
df79e93
Updated npm
WillTheDeveloper Jun 20, 2022
5f9ffdb
Updated all packages
WillTheDeveloper Jun 25, 2022
6404e10
Changed scout driver
WillTheDeveloper Jun 25, 2022
ac70aff
Updated packages
WillTheDeveloper Jul 2, 2022
5f5472a
Trying to fix group/discussion issue
WillTheDeveloper Jul 15, 2022
3d9d817
Updated packages
WillTheDeveloper Jul 20, 2022
fd6f899
Merge branch 'master' into group-discussion-board
WillTheDeveloper Jul 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions app/Http/Controllers/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Http\Controllers;

use App\Http\Requests\CreateNewGroup;
use App\Models\Discussion;
use App\Models\Reply;
use App\Models\Subject;
use App\Models\Group as UserGroup;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -83,4 +85,73 @@ public function updatename($id, Request $request)

return redirect(route('groups.manage', $id));
}

public function discussion($id)
{
return view('groupdiscussions', [
'board' => Discussion::query()->where('discussions.group_id', $id)->orderByDesc('discussions.created_at')->paginate(),
'id' => $id
]);
}

public function newdiscussion($id, Request $request)
{
Discussion::query()->create(
[
'title' => $request->input('title'),
'body' => $request->input('description'),
'user_id' => auth()->id(),
'locked' => 0,
'group_id' => $id //This is wrong, should be group id, this ID is the discussion id.
]
)->save();

return redirect(route('group.discussion', $id));
}

public function lock($id)
{
Discussion::query()->where('id', $id)->update(['locked' => 1]);

return redirect(route('group.discussion', $id));
}

public function unlock($id)
{
Discussion::query()->where('id', $id)->update(['locked' => 0]);

return redirect(route('group.discussion', $id));
}

public function deletediscussion($id)
{
Discussion::query()->where('id', $id)->delete();
Reply::query()->where('discussion_id', $id)->delete();

return redirect(route('dashboard'));
}

public function replies($id)
{
return view('discussionschat', [
'main' => Discussion::query()->where('discussions.id', $id)->orderByDesc('created_at')->firstOrFail(),
'replies' => Reply::query()->where('replies.discussion_id', $id)->orderByDesc('created_at')->get()
]);
}

public function reply($id, Request $request)
{
$d = Discussion::query()->where('discussions.id', $id)->get('id')->first()->id;

Reply::query()->create(
[
'user_id' => auth()->id(),
'message' => $request->input('message'),
'group_id' => $id, // furthermore this is incorrect.
'discussion_id' => $d
]
)->save();

return redirect(route('discussions.replies', $id));
}
}
28 changes: 28 additions & 0 deletions app/Models/Discussion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Discussion extends Model
{
use HasFactory;

protected $fillable = [
'title',
'body',
'group_id',
'user_id'
];

public function Reply()
{
return $this->hasMany(Reply::class);
}

public function User()
{
return $this->belongsTo(User::class);
}
}
28 changes: 28 additions & 0 deletions app/Models/Reply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Reply extends Model
{
use HasFactory;

protected $fillable = [
'user_id',
'message',
'group_id',
'discussion_id'
];

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

public function User()
{
return $this->belongsTo(User::class);
}
}
10 changes: 10 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public function Report()
return $this->hasMany(Report::class);
}

public function Discussion()
{
return $this->hasMany(Discussion::class);
}

public function Reply()
{
return $this->hasMany(Reply::class);
}

public function Webhook()
{
return $this->hasMany(Webhook::class);
Expand Down
29 changes: 29 additions & 0 deletions database/factories/DiscussionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Database\Factories;

use App\Models\Group;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Discussion>
*/
class DiscussionFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'title' => $this->faker->title,
'body' => $this->faker->paragraph,
'group_id' => Group::query()->get('id')->random(),
'user_id' => User::query()->get('id')->random(),
'locked' => $this->faker->boolean
];
}
}
29 changes: 29 additions & 0 deletions database/factories/ReplyFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Database\Factories;

use App\Models\Discussion;
use App\Models\Group;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Reply>
*/
class ReplyFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'message' => $this->faker->paragraph,
'user_id' => User::query()->get('id')->random(),
'group_id' => Group::query()->get('id')->random(),
'discussion_id' => Discussion::query()->get('id')->random()
];
}
}
36 changes: 36 additions & 0 deletions database/migrations/2022_05_28_092615_create_discussions_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('discussions', function (Blueprint $table) {
$table->id();
$table->text('title');
$table->text('body');
$table->integer('group_id');
$table->boolean('locked')->default(0);
$table->integer('user_id');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('discussions');
}
};
35 changes: 35 additions & 0 deletions database/migrations/2022_05_28_092705_create_replies_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('replies', function (Blueprint $table) {
$table->id();
$table->integer('user_id');
$table->text('message');
$table->integer('group_id');
$table->integer('discussion_id');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('replies');
}
};
24 changes: 24 additions & 0 deletions package-lock.json

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

1 change: 0 additions & 1 deletion resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class="origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg bg-white

</div>


<div class="mt-8">
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
{{-- <h2 class="text-lg leading-6 font-medium text-gray-900">Overview</h2>--}}
Expand Down
Loading