Skip to content

Commit

Permalink
fix has scope
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 10, 2023
1 parent 85a6648 commit 09828f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
5 changes: 1 addition & 4 deletions app/Http/Controllers/Dashboard/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ class ProjectController extends Controller
{
public function index(Request $request)
{
// TODO: fix issue with approved projects not being displayed
$projectStatus = $request->get('project_status');


return Inertia::render('AdminOng/Projects/Projects', [
'query' => ProjectCardResource::collection(
Project::query()
->where('organization_id', auth()->user()->organization_id)
->when($projectStatus, function (Builder $query) use ($projectStatus) {
return $query->statusIs($projectStatus);
})
->where('organization_id', auth()->user()->organization_id)
->paginate(16)
->withQueryString()
),
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Requests/RegistrationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function rules(): array
$rules = array_merge($rules, [
'ngo' => ['array', 'required'],
'ngo.name' => ['string', 'required'],
'ngo.description' => ['string', 'required'],
'ngo.description' => ['string', 'required', 'max:1000'],
'ngo.logo' => ['required', 'image'],
'ngo.statute' => ['required', 'file'],
'ngo.street_address' => ['string', 'required'],
Expand All @@ -39,8 +39,8 @@ public function rules(): array
'ngo.domains' => ['array', 'required'],
'ngo.counties' => ['array', 'required'],
'ngo.volunteer' => ['boolean'],
'ngo.why_volunteer' => ['string', 'nullable'],
'ngo.website' => ['string', 'nullable'],
'ngo.why_volunteer' => ['string', 'nullable', 'max:1000'],
'ngo.website' => ['string', 'nullable', 'url'],
]);
}

Expand Down
20 changes: 10 additions & 10 deletions app/Traits/HasProjectStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public function scopeWhereIsOpen(Builder $query): Builder
->whereDate('end', '>=', now());
}

public function scopeWhereStartsSoon(): Builder
public function scopeWhereStartsSoon(Builder $query): Builder
{
return $this->whereIsPublished()
return $query->whereIsPublished()
->whereDate('start', '>=', now())
->orderBy('start');
}
Expand All @@ -72,14 +72,14 @@ public function scopeWhereIsDraft(Builder $query): Builder
public function scopeStatusIs(Builder $query, $status): Builder
{
return match ($status) {
'draft' => $this->whereIsDraft(),
'pending' => $this->whereIsPending(),
'approved' => $this->whereIsApproved(),
'rejected' => $this->whereIsRejected(),
'published' => $this->whereIsPublished(),
'open' => $this->whereIsOpen(),
'starts_soon' => $this->whereStartsSoon(),
default => $this->newQuery(),
'draft' => $query->whereIsDraft(),
'pending' => $query->whereIsPending(),
'approved' => $query->whereIsApproved(),
'rejected' => $query->whereIsRejected(),
'published' => $query->whereIsPublished(),
'open' => $query->whereIsOpen(),
'starts_soon' => $query->whereStartsSoon(),
default => $query,
};
}
}

0 comments on commit 09828f8

Please sign in to comment.