Prompt: when user logs in for the first time, they should see a modal asking to create an organization (only name input for organization). Keep the design similar to homepage/login/register in terms of color scheme. User should not be able to delete ALL organization they have, to have at least one is mendatory
Session: Total cost: $5.44 (costs may be inaccurate due to usage of unknown models) Total duration (API): 50m 49s Total duration (wall): 1h 10m 53s Total code changes: 2972 lines added, 29 lines removed Usage by model: qwen/qwen3.6-35b-a3b: 287.3k input, 69.6k output, 11.5m cache read, 0 cache write ($5.37) claude-haiku-4-5: 9.4k input, 13.3k output, 8.3k cache read, 0 cache write ($0.0767) Runtime: llamacpp Model: Qwen 3.6 35B A3B Q4 K M Coding Agent: ClaudeCode
This commit is contained in:
62
app/Http/Controllers/OrganizationController.php
Normal file
62
app/Http/Controllers/OrganizationController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Organization;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class OrganizationController extends Controller
|
||||
{
|
||||
public function show(Organization $organization)
|
||||
{
|
||||
abort_unless($organization->user_id === auth()->id(), 403);
|
||||
return view('organizations.show', compact('organization'));
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse|RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
$user->organizations()->create(['name' => $validated['name']]);
|
||||
$user->update(['has_organization' => true]);
|
||||
|
||||
return response()->json([
|
||||
'redirect' => route('dashboard'),
|
||||
'message' => 'Organization created successfully.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function switch(Organization $organization)
|
||||
{
|
||||
abort_unless($organization->user_id === auth()->id(), 403);
|
||||
auth()->user()->update(['current_organization_id' => $organization->id]);
|
||||
return redirect()->route('organizations.show', $organization);
|
||||
}
|
||||
|
||||
public function destroy(Organization $organization): JsonResponse|RedirectResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
if ($organization->user_id !== $user->id) {
|
||||
return response()->json(['error' => 'Unauthorized'], 403);
|
||||
}
|
||||
|
||||
if ($user->organizations()->count() <= 1) {
|
||||
return response()->json([
|
||||
'error' => 'You must have at least one organization.',
|
||||
]);
|
||||
}
|
||||
|
||||
$organization->delete();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Organization deleted.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
27
app/Models/Organization.php
Normal file
27
app/Models/Organization.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Organization extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['user_id', 'name'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,27 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Models\Organization;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Fillable(['name', 'email', 'password', 'has_organization', 'current_organization_id'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
public function organizations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Organization::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user