Initial Commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Booking;
|
||||
use App\Models\DjProfile;
|
||||
use App\Models\Review;
|
||||
use App\Models\User;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
return view('admin.dashboard', ['stats' => ['users' => User::count(), 'djs' => DjProfile::count(), 'bookings' => Booking::count(), 'reviews' => Review::where('status', 'pending')->count()]]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller {}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\DjProfile;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DjController extends Controller
|
||||
{
|
||||
public function index(Request $r)
|
||||
{
|
||||
$q = DjProfile::query()->where('is_published', true)->with('genres');
|
||||
if ($r->filled('location')) {
|
||||
$q->where('city', 'like', '%'.$r->string('location').'%');
|
||||
} if ($r->filled('max_price')) {
|
||||
$q->where('price_from', '<=', $r->integer('max_price'));
|
||||
}
|
||||
|
||||
return view('djs.index', ['djs' => $q->orderByDesc('is_featured')->orderByDesc('average_rating')->paginate(12)->withQueryString()]);
|
||||
}
|
||||
|
||||
public function show(DjProfile $djProfile)
|
||||
{
|
||||
abort_unless($djProfile->is_published, 404);
|
||||
|
||||
return view('djs.show', ['dj' => $djProfile->load(['genres', 'reviews' => fn ($q) => $q->where('status', 'published')->latest()])]);
|
||||
}
|
||||
|
||||
public function apiIndex()
|
||||
{
|
||||
return DjProfile::where('is_published', true)->with('genres')->paginate(20);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\DjProfile;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EnquiryController extends Controller
|
||||
{
|
||||
public function store(Request $r, DjProfile $djProfile)
|
||||
{
|
||||
$data = $r->validate(['event_type' => 'required|string|max:80', 'event_date' => 'required|date|after_or_equal:today', 'venue' => 'required|string|max:160', 'postcode' => 'nullable|string|max:12', 'guest_count' => 'nullable|integer|min:1|max:100000', 'budget' => 'nullable|numeric|min:0', 'message' => 'required|string|max:5000']);
|
||||
$djProfile->enquiries()->create($data + ['user_id' => $r->user()->id, 'status' => 'new']);
|
||||
|
||||
return back()->with('success', 'Your enquiry has been sent.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\DjProfile;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('home.index', ['featured' => DjProfile::where('is_published', true)->where('is_featured', true)->orderByDesc('average_rating')->limit(5)->get()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ReviewController extends Controller
|
||||
{
|
||||
public function store(Request $r, Booking $booking)
|
||||
{
|
||||
abort_unless($booking->client_id === $r->user()->id && $booking->status === 'completed', 403);
|
||||
$d = $r->validate(['rating' => 'required|integer|min:1|max:5', 'title' => 'nullable|string|max:100', 'body' => 'required|string|max:3000']);
|
||||
$booking->djProfile?->reviews()->create($d + ['booking_id' => $booking->id, 'user_id' => $r->user()->id, 'status' => 'pending']);
|
||||
|
||||
return back()->with('success', 'Review submitted for moderation.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Booking extends Model
|
||||
{
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = ['enquiry_id', 'client_id', 'dj_profile_id', 'event_date', 'total', 'deposit', 'status', 'paid_at'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['event_date' => 'date', 'total' => 'decimal:2', 'deposit' => 'decimal:2', 'paid_at' => 'datetime'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Business extends Model
|
||||
{
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = ['name', 'slug', 'description', 'email', 'phone', 'website', 'status', 'verified_at'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['verified_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(User::class)->withPivot(['role'])->withTimestamps();
|
||||
}
|
||||
|
||||
public function profiles()
|
||||
{
|
||||
return $this->hasMany(DjProfile::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DjProfile extends Model
|
||||
{
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = ['user_id', 'business_id', 'stage_name', 'slug', 'headline', 'bio', 'city', 'service_radius_miles', 'price_from', 'profile_photo', 'cover_photo', 'verified_at', 'is_featured', 'is_published', 'average_rating', 'review_count'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['verified_at' => 'datetime', 'is_featured' => 'boolean', 'is_published' => 'boolean', 'price_from' => 'decimal:2', 'average_rating' => 'decimal:2'];
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function business()
|
||||
{
|
||||
return $this->belongsTo(Business::class);
|
||||
}
|
||||
|
||||
public function genres()
|
||||
{
|
||||
return $this->belongsToMany(Genre::class);
|
||||
}
|
||||
|
||||
public function reviews()
|
||||
{
|
||||
return $this->hasMany(Review::class);
|
||||
}
|
||||
|
||||
public function enquiries()
|
||||
{
|
||||
return $this->hasMany(Enquiry::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Enquiry extends Model
|
||||
{
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = ['user_id', 'dj_profile_id', 'event_type', 'event_date', 'start_time', 'end_time', 'venue', 'postcode', 'guest_count', 'budget', 'message', 'status'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['event_date' => 'date', 'budget' => 'decimal:2'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Genre extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'slug'];
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Review extends Model
|
||||
{
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = ['booking_id', 'user_id', 'dj_profile_id', 'rating', 'title', 'body', 'status', 'dj_reply'];
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens,HasRoles,Notifiable;
|
||||
|
||||
protected $fillable = ['name', 'email', 'password', 'phone', 'avatar_path', 'marketing_opt_in'];
|
||||
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['email_verified_at' => 'datetime', 'password' => 'hashed', 'marketing_opt_in' => 'boolean'];
|
||||
}
|
||||
|
||||
public function businesses()
|
||||
{
|
||||
return $this->belongsToMany(Business::class)->withPivot(['role'])->withTimestamps();
|
||||
}
|
||||
|
||||
public function djProfile()
|
||||
{
|
||||
return $this->hasOne(DjProfile::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user