Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME=Bursa binelui
APP_NAME="Bursa binelui"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
Expand All @@ -14,7 +14,7 @@ DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=bursa_binelui
DB_USERNAME=bursa_binelui
DB_USERNAME=
DB_PASSWORD=

BROADCAST_DRIVER=log
Expand Down
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,63 @@ If you would like to suggest new functionality, open an Issue and mark it as a _

Mention all related repos and projects.

## Development

### Running the app
- After initial setup (below), run `npm run dev`
- If using Laravel Herd/Valet, access your app in the browser at `https://bursabinelui.test`
- If using the built-in PHP server:
- run `php artisan:serve`
- access your app in the browser at `http://127.0.0.1:8000`

### Initial setup
<details>
<summary>See initial setup</strong></summary>

#### 1. Create local database `bursa_binelui`

#### 2. Copy `.env.example`, rename it to `.env` and fill in your database information

#### 3. Install composer dependencies
```bash
composer install
```

#### 4. Install npm dependencies
```bash
npm install
```

#### 5. Generate the app secret key
```bash
php artisan key:generate
```

#### 6. Migrate and seed the database
```bash
php artisan migrate:fresh --seed
```
> **Note:** Seeding may fail due to underlying issues with Faker date generation. If that happens, just rerun `php artisan migrate:fresh --seed`. Also, seeding can take a while, so be patient.

#### 7. Add the following line to your `.env` file to disable CSP locally
```bash
CSP_ENABLED=false
```

> **Note:** Only for local development!

#### 8. Configure local development URL
#### 8.1. If using Laravel Herd (macOS, Windows)
- **Install Laravel Herd**
Visit [https://herd.laravel.com](https://herd.laravel.com) and download the installer for macOS or Windows
- **Open your project with Herd**
- Launch Herd. Go to `Sites`. Go to `Add Sites`. Go to `Link existing project`. Select the project. Select the `PHP version` and `enable HTTPS`. Click `Next`
- ![](https://i.imgur.com/YYhxeVK.png)

#### 8.2. If using the built-in PHP server
- In your `.env` file, update `APP_URL` to `APP_URL=http://127.0.0.1:8000`
</details>

## Deployment

Guide users through getting your code up and running on their own system. In this section you can talk about:
Expand Down
5 changes: 5 additions & 0 deletions app/Filament/Resources/Articles/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public static function form(Form $form): Form
->relationship('category', 'name')
->required(),

TextInput::make('cover_photo_url')
->label(__('article.cover_photo_url'))
->url()
->maxLength(255),

TiptapEditor::make('content')
->label(__('article.content'))
->extraInputAttributes([
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function index()

'projects' => ProjectCardResource::collection(
Project::whereIsOpen()
->whereHasValidDates('start','end')
->latest()
->limit(12)
->get()
Expand All @@ -37,6 +38,7 @@ public function index()
'bcr_projects' => BCRProjectCardResource::collection(
BCRProject::query()
->where('status', ProjectStatus::approved)
->whereHasValidDates()
->latest()
->with('county')
->limit(12)
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ protected function projectList(Request $request, string $view): Response
AllowedSort::custom('donations_count', new ProjectDonationsCountSort),
])
->defaultSort('-id')
->whereIsPublished();
->whereIsPublished()
->whereHasValidDates('start', 'end');

return Inertia::render('Public/Projects/Index', [
'view' => $view,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/Articles/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function toArray(Request $request): array
return [
'id' => $this->id,
'title' => $this->title,
'cover_photo_url' => $this->cover_photo_url ?? '#',
'description' => Str::of($this->content)
->stripTags()
->limit(200),
Expand Down
1 change: 1 addition & 0 deletions app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Article extends Model implements HasMedia
'slug',
'content',
'article_category_id',
'cover_photo_url',
'author',
];

Expand Down
8 changes: 5 additions & 3 deletions app/Models/BCRProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Concerns\HasSlug;
use App\Enums\ProjectStatus;
use App\Traits\HasProjectStatus;
use App\Traits\HasValidDates;
use Embed\Embed;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -23,6 +24,7 @@ class BCRProject extends Model implements HasMedia
{
use HasFactory;
use HasLocation;
use HasValidDates;
use InteractsWithMedia;
use HasProjectStatus;
use HasSlug;
Expand Down Expand Up @@ -90,12 +92,12 @@ public function getEmbeddedVideosAttribute(): array
{
return collect($this->videos)
->pluck('link')
->filter(fn ($video) => ! blank($video))
->filter(fn($video) => ! blank($video))
->map(
fn (string $videoUrl) => Cache::remember(
fn(string $videoUrl) => Cache::remember(
'video-' . hash('sha256', $videoUrl),
MONTH_IN_SECONDS,
fn () => rescue(fn () => (new Embed)->get($videoUrl)->code, '', false)
fn() => rescue(fn() => (new Embed)->get($videoUrl)->code, '', false)
)
)
->filter()
Expand Down
14 changes: 8 additions & 6 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Enums\EuPlatescStatus;
use App\Enums\ProjectStatus;
use App\Traits\HasProjectStatus;
use App\Traits\HasValidDates;
use Embed\Embed;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand Down Expand Up @@ -39,6 +40,7 @@ class Project extends Model implements HasMedia
use HasVolunteers;
use InteractsWithMedia;
use HasProjectStatus;
use HasValidDates;
use HasSlug;
use LogsActivity;
use LogsActivityForApproval;
Expand Down Expand Up @@ -192,14 +194,14 @@ public function getIsDraftAttribute(): bool

public function getIsPeriodActiveAttribute(): bool
{
return $this->start->isPast() && $this->end->isFuture();
return $this->start?->isPast() && $this->end?->isFuture();
}

public function getIsActiveAttribute(): bool
{
return $this->status == ProjectStatus::approved
&& $this->start->isPast()
&& $this->end->isFuture();
&& $this->start?->isPast()
&& $this->end?->isFuture();
}

public function getCanBeArchivedAttribute(): bool
Expand Down Expand Up @@ -249,7 +251,7 @@ public function markAsApproved(): bool
$slug .= '-' . ($count + 1);
}

$this->activities->map(fn (Activity $activity) => $activity->approve());
$this->activities->map(fn(Activity $activity) => $activity->approve());

return $this->update([
'status' => ProjectStatus::approved,
Expand Down Expand Up @@ -280,10 +282,10 @@ public function getEmbeddedVideosAttribute(): array
->pluck('url')
->filter()
->map(
fn (string $videoUrl) => Cache::remember(
fn(string $videoUrl) => Cache::remember(
'video-' . hash('sha256', $videoUrl),
MONTH_IN_SECONDS,
fn () => rescue(fn () => (new Embed)->get($videoUrl)->code, report: false)
fn() => rescue(fn() => (new Embed)->get($videoUrl)->code, report: false)
)
)
->filter()
Expand Down
17 changes: 11 additions & 6 deletions app/Notifications/Admin/ExportExcelNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,20 @@ public function via(object $notifiable): array
*/
public function toMail(object $notifiable): MailMessage
{
$file = Storage::disk('filament-excel')->exists($this->filename)
? Storage::disk('filament-excel')->get($this->filename)
: null;

return (new MailMessage)
$mail = (new MailMessage)
->subject(__('notification.export_finished.title'))
->line(__('notification.export_finished.body', ['filename' => $this->filename]))
->attachData($file, $this->filename)
->action(__('notification.export_finished.action'), $this->generateURL());

if (Storage::disk('filament-excel')->exists($this->filename)) {
$mail->attachData(
Storage::disk('filament-excel')->get($this->filename),
$this->filename,
['mime' => Storage::disk('filament-excel')->mimeType($this->filename)]
);
}

return $mail;
}

/**
Expand Down
16 changes: 16 additions & 0 deletions app/Traits/HasValidDates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Traits;

use Illuminate\Database\Eloquent\Builder;

trait HasValidDates
{
public function scopeWhereHasValidDates(Builder $query, string $startColumn = 'start_date', string $endColumn = 'end_date'): Builder
{
return $query
->whereNotNull($startColumn)
->whereNotNull($endColumn)
->whereColumn($startColumn, '<=', $endColumn);
}
}
Loading
Loading