feat: product team members

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Doar Mihai
2026-10-17 16:04:25 +03:00
co-authored by Claude Sonnet 5.5
parent 768c814762
commit fbb4862454
11 changed files with 321 additions and 5 deletions
+14 -4
View File
@@ -112,7 +112,7 @@ class ProductController extends Controller
'category_id' => 'required|exists:categories,id',
'tags' => 'nullable|array',
'tags.*' => 'exists:tags,id',
] + $this->detailRules());
] + $this->detailRules(Auth::id()));
foreach (array_keys(Product::BADGES) as $badge) {
$validated[$badge] = $request->boolean($badge);
@@ -150,7 +150,7 @@ class ProductController extends Controller
abort(404);
}
$product->load(['user', 'category', 'tags', 'comments.user', 'upvotes', 'bookmarks']);
$product->load(['user', 'category', 'tags', 'members', 'comments.user', 'upvotes', 'bookmarks']);
return view('products.show', compact('product'));
}
@@ -182,7 +182,7 @@ class ProductController extends Controller
'category_id' => 'required|exists:categories,id',
'tags' => 'nullable|array',
'tags.*' => 'exists:tags,id',
] + $this->detailRules());
] + $this->detailRules($product->user_id));
// Badges are locked for non-moderators once the product is approved
if ($product->status !== 'approved' || Auth::user()->hasAnyRole(['moderator', 'admin'])) {
@@ -218,7 +218,7 @@ class ProductController extends Controller
/**
* Validation rules for the product detail fields.
*/
protected function detailRules(): array
protected function detailRules(int $ownerId): array
{
return [
'free_tier' => 'boolean',
@@ -234,6 +234,9 @@ class ProductController extends Controller
'plans.*.price' => 'required|numeric|min:0|max:99999',
'plans.*.period' => ['required', Rule::in(PricingPlan::PERIODS)],
'plans.*.description' => 'nullable|string|max:255',
'members' => 'nullable|array',
'members.*.user_id' => ['required', 'distinct', 'exists:users,id', Rule::notIn([$ownerId])],
'members.*.role' => 'required|string|max:100',
];
}
@@ -254,6 +257,13 @@ class ProductController extends Controller
]);
}
// The submitted member list replaces all existing members
$members = [];
foreach ((array) $request->input('members', []) as $member) {
$members[$member['user_id']] = ['role' => $member['role']];
}
$product->members()->sync($members);
// Only rows belonging to this product may be removed
$ids = array_filter((array) $request->input('remove_screenshots', []));
if ($ids) {
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UserSearchController extends Controller
{
/**
* Search users by name (only public identifiers are returned).
*/
public function __invoke(Request $request): JsonResponse
{
$q = trim((string) $request->query('q', ''));
if (mb_strlen($q) < 2) {
return response()->json([]);
}
$escaped = addcslashes($q, '\\%_');
return response()->json(
User::query()
->where('name', 'like', "%{$escaped}%")
->orderBy('name')
->limit(10)
->get(['id', 'name', 'slug'])
->map(fn (User $u) => ['id' => $u->id, 'name' => $u->name, 'slug' => $u->slug])
->values()
);
}
}
+11
View File
@@ -138,6 +138,17 @@ class Product extends Model
return $this->hasMany(PricingPlan::class)->orderBy('position')->orderBy('id');
}
/**
* Get the team members of the product (besides the submitter).
*/
public function members(): BelongsToMany
{
return $this->belongsToMany(User::class, 'product_members')
->withPivot('role')
->withTimestamps()
->orderBy('product_members.id');
}
/**
* Get the user that owns the product.
*/