mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add Circle controller,model and migration
This commit is contained in:
parent
758677ada4
commit
e00f65da03
3 changed files with 144 additions and 0 deletions
38
app/Circle.php
Normal file
38
app/Circle.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Circle extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'bcc',
|
||||
'scope',
|
||||
'active'
|
||||
];
|
||||
|
||||
public function members()
|
||||
{
|
||||
return $this->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}");
|
||||
}
|
||||
}
|
69
app/Http/Controllers/CircleController.php
Normal file
69
app/Http/Controllers/CircleController.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Auth;
|
||||
use App\{
|
||||
Circle,
|
||||
CircleProfile,
|
||||
Profile,
|
||||
Status,
|
||||
};
|
||||
|
||||
class CircleController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->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'));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCirclesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('circles', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue