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
18 changes: 18 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
# Enable the FrankenPHP module globally
frankenphp
# Disable the admin API to prevent host conflicts on Render
admin off
}

# Listen on port 8080 (unprivileged port for Render)
:8080 {
root * /app/public
encode gzip

# Enable the FrankenPHP server
php_server

# Handle static files
file_server
}
26 changes: 19 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ FROM dunglas/frankenphp:1.4-php8.4-alpine
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser \
COMPOSER_ALLOW_SUPERUSER=1 \
SERVER_NAME=:80 \
PUBLIC_ROOT=/app/public
SERVER_NAME=:8080 \
PUBLIC_ROOT=/app/public \
LOG_CHANNEL=stderr

# Install system dependencies
RUN apk add --no-cache \
Expand All @@ -25,7 +26,8 @@ RUN apk add --no-cache \
postgresql-dev \
git \
unzip \
bash
bash \
libcap

# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
Expand All @@ -40,7 +42,9 @@ RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
&& pecl install redis \
&& docker-php-ext-enable redis \
&& apk del .build-deps
&& apk del .build-deps \
&& setcap -r /usr/local/bin/frankenphp \
&& apk del libcap

# Set working directory
WORKDIR /app
Expand Down Expand Up @@ -75,7 +79,15 @@ RUN { \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

# Expose port 80
EXPOSE 80
# Copy custom Caddyfile
COPY Caddyfile /etc/caddy/Caddyfile

# The entrypoint is already set to frankenphp in the base image
# Copy entrypoint script and set permissions
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Expose port 8080
EXPOSE 8080

# Use the entrypoint script to run migrations and start the server
CMD ["/usr/local/bin/entrypoint.sh"]
13 changes: 10 additions & 3 deletions app/View/Components/AdminDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,23 @@ public function __construct()
$this->totalcarpoolVehicles = CarpoolVehicle::count('id');

// Request approval rate
$this->requestApprovalRate = number_format((TransportRequest::where('status', 'Approved')->count() / $this->totalTransportRequests) * 100, 2);
$total = $this->totalTransportRequests;
$this->requestApprovalRate = $total > 0
? number_format((TransportRequest::where('status', 'Approved')->count() / $total) * 100, 2)
: 0;

// Peak request month
$this->peakRequestMonth = TransportRequest::selectRaw('EXTRACT(MONTH FROM event_date) as month, count(*) as requests')
$peak = TransportRequest::selectRaw('EXTRACT(MONTH FROM event_date) as month, count(*) as requests')
->groupBy('month')
->orderBy('requests', 'desc')
->first();

// Return the month name
$this->peakRequestMonth = date('F', mktime(0, 0, 0, $this->peakRequestMonth->month, 10));
if ($peak && $peak->month) {
$this->peakRequestMonth = date('F', mktime(0, 0, 0, $peak->month, 10));
} else {
$this->peakRequestMonth = 'N/A';
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies(at: '*');
$middleware->append([
\App\Http\Middleware\SecurityHeaders::class,
\App\Http\Middleware\CheckIfActive::class,
Expand Down
12 changes: 9 additions & 3 deletions database/seeders/RolePermissionSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Spatie\Permission\PermissionRegistrar;

class RolePermissionSeeder extends Seeder
{
Expand All @@ -14,6 +15,9 @@ class RolePermissionSeeder extends Seeder
*/
public function run(): void
{
// Reset cache
app(PermissionRegistrar::class)->forgetCachedPermissions();

// Create permissions
$permissions = [
'view student dashboard',
Expand All @@ -33,7 +37,7 @@ public function run(): void
];

foreach ($permissions as $permission) {
Permission::create(['name' => $permission]);
Permission::firstOrCreate(['name' => $permission]);
}

/* Create roles and assign permissions */
Expand Down Expand Up @@ -74,8 +78,10 @@ public function run(): void
];

foreach ($rolePermissions as $roleName => $permissions) {
$role = Role::create(['name' => $roleName]);
$role->givePermissionTo($permissions);
$role = Role::firstOrCreate(['name' => $roleName]);

// Sync permissions
$role->syncPermissions($permissions);
}


Expand Down
18 changes: 10 additions & 8 deletions database/seeders/UserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ public function run(): void
foreach ($users as $userData) {
$password = Str::random(12);

$user = User::create([
'name' => $userData['name'],
'email' => $userData['email'],
'password' => bcrypt($password),
'phone' => '+254712345678',
'account_status' => 'active',
'email_verified_at' => now(),
]);
$user = User::firstOrCreate(
['email' => $userData['email']],
[
'name' => $userData['name'],
'password' => bcrypt($password),
'phone' => '+254700000000',
'account_status' => 'active',
'email_verified_at' => now(),
]
);

if ($userData['role']) {
$user->assignRole($userData['role']);
Expand Down
18 changes: 18 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e

# Run migrations automatically on startup
echo "[ENTRYPOINT] Running migrations..."
php artisan migrate --force

# Run RolePermissionSeeder
echo "[ENTRYPOINT] Running RolePermissionSeeder..."
php artisan db:seed --class=RolePermissionSeeder --force

# Run UserSeeder
echo "[ENTRYPOINT] Running UserSeeder..."
php artisan db:seed --class=UserSeeder --force

# Execute the main container command (FrankenPHP)
echo "[ENTRYPOINT] Starting FrankenPHP..."
exec frankenphp run --config /etc/caddy/Caddyfile
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<h1 class="max-w-2xl mb-4 text-4xl font-extrabold leading-none md:text-5xl xl:text-6xl dark:text-white">
StrathPort</h1>
<p
class="max-w-2xl mb-6 font-light text-gray-800 dark:text-gray-500 lg:mb-8 md:text-lg lg:text-xl dark:text-gray-400">
class="max-w-2xl mb-6 font-light text-gray-800 dark:text-gray-500 lg:mb-8 md:text-lg lg:text-xl">
Sign up now to take a step towards a smoother, safer, journey!</p>
<a href="{{ route('register') }}"
class="inline-flex items-center justify-center px-5 py-3 mr-3 text-base font-medium text-center text-white transition ease-in-out delay-150 rounded-lg hover:-translate-y-1 hover:scale-125 bg-fuchsia-700 hover:bg-fuchsia-800 focus:ring-4 focus:ring-pink-300 dark:focus:ring-fuchsia-900">
Expand Down
Loading