This repository has been archived by the owner on Mar 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added initial migration, model and controller for group feature. see #…
- Loading branch information
Showing
5 changed files
with
165 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Group extends Model | ||
{ | ||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'name', 'description', 'avatar', | ||
'background', 'visibility', | ||
]; | ||
|
||
|
||
public function content() | ||
{ | ||
return $this->belongsToMany('App\Content'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class GroupMembers extends Model | ||
{ | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'group_id', 'user_id', 'status', 'is_moderator', | ||
]; | ||
|
||
/** | ||
* Get the user | ||
*/ | ||
public function user() | ||
{ | ||
return $this->belongsTo('App\User'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class GroupController extends Controller | ||
{ | ||
|
||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
// | ||
} | ||
|
||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request, $id) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
// | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
database/migrations/2020_03_05_203451_add_groups_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class AddGroupsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
|
||
Schema::table('contents', function (Blueprint $table) { | ||
$table->unsignedInteger('group_id')->after('user_id'); | ||
}); | ||
|
||
Schema::create('groups', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->string('name'); | ||
$table->string('avatar'); | ||
$table->string('background'); | ||
$table->text('description'); | ||
$table->enum('visibility', ['public', 'private']); | ||
$table->timestamps(); | ||
|
||
}); | ||
|
||
Schema::create('group_members', function (Blueprint $table) { | ||
$table->unsignedBigInteger('group_id'); | ||
$table->unsignedBigInteger('user_id'); | ||
$table->enum('status', ['confirmed', 'awaiting', 'blocking']); | ||
$table->tinyInteger('is_moderator'); | ||
$table->foreign('group_id')->references('id')->on('contents')->onDelete('cascade'); | ||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters