diff --git a/app/Circle.php b/app/Circle.php new file mode 100644 index 000000000..fdce9fcd0 --- /dev/null +++ b/app/Circle.php @@ -0,0 +1,38 @@ +hasManyThrough( + Profile::class, + CircleProfile::class, + 'circle_id', + 'id', + 'id', + 'profile_id' + ); + } + + public function owner() + { + return $this->belongsTo(Profile::class, 'profile_id'); + } + + public function url() + { + return url("/i/circle/show/{$this->id}"); + } +} diff --git a/app/Http/Controllers/CircleController.php b/app/Http/Controllers/CircleController.php new file mode 100644 index 000000000..24423ee88 --- /dev/null +++ b/app/Http/Controllers/CircleController.php @@ -0,0 +1,69 @@ +middleware('auth'); + } + + public function home(Request $request) + { + $circles = Circle::whereProfileId(Auth::user()->profile->id) + ->orderByDesc('created_at') + ->paginate(10); + return view('account.circles.home', compact('circles')); + } + + public function create(Request $request) + { + return view('account.circles.create'); + } + + public function store(Request $request) + { + $this->validate($request, [ + 'name' => 'required|string|min:1', + 'description' => 'nullable|string|max:255', + 'scope' => [ + 'required', + 'string', + Rule::in([ + 'public', + 'private', + 'unlisted', + 'exclusive' + ]) + ], + ]); + + $circle = Circle::firstOrCreate([ + 'profile_id' => Auth::user()->profile->id, + 'name' => $request->input('name') + ], [ + 'description' => $request->input('description'), + 'scope' => $request->input('scope'), + 'active' => false + ]); + + return redirect(route('account.circles')); + } + + public function show(Request $request, $id) + { + $circle = Circle::findOrFail($id); + return view('account.circles.show', compact('circle')); + } +} diff --git a/database/migrations/2019_02_09_045935_create_circles_table.php b/database/migrations/2019_02_09_045935_create_circles_table.php new file mode 100644 index 000000000..40faf510e --- /dev/null +++ b/database/migrations/2019_02_09_045935_create_circles_table.php @@ -0,0 +1,37 @@ +bigIncrements('id'); + $table->bigInteger('profile_id')->unsigned()->index(); + $table->string('name')->nullable(); + $table->text('description')->nullable(); + $table->string('scope')->default('public'); + $table->boolean('bcc')->default(false); + $table->boolean('active')->default(false)->index(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('circles'); + } +}