From 8355d57fc46baf7cc1fbd5458e59520fabd841c7 Mon Sep 17 00:00:00 2001 From: James Shiffer Date: Wed, 5 Nov 2025 02:18:59 -0800 Subject: [PATCH] Boilerplate for Listing resource --- app/Http/Controllers/ListingController.php | 66 +++++++++++++++++++ app/Http/Requests/StoreListingRequest.php | 28 ++++++++ app/Http/Requests/UpdateListingRequest.php | 28 ++++++++ app/Models/Listing.php | 12 ++++ app/Policies/ListingPolicy.php | 66 +++++++++++++++++++ database/factories/ListingFactory.php | 23 +++++++ ...025_11_05_094705_create_listings_table.php | 33 ++++++++++ database/seeders/ListingSeeder.php | 17 +++++ routes/api.php | 3 + 9 files changed, 276 insertions(+) create mode 100644 app/Http/Controllers/ListingController.php create mode 100644 app/Http/Requests/StoreListingRequest.php create mode 100644 app/Http/Requests/UpdateListingRequest.php create mode 100644 app/Models/Listing.php create mode 100644 app/Policies/ListingPolicy.php create mode 100644 database/factories/ListingFactory.php create mode 100644 database/migrations/2025_11_05_094705_create_listings_table.php create mode 100644 database/seeders/ListingSeeder.php diff --git a/app/Http/Controllers/ListingController.php b/app/Http/Controllers/ListingController.php new file mode 100644 index 0000000..19db2ce --- /dev/null +++ b/app/Http/Controllers/ListingController.php @@ -0,0 +1,66 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Http/Requests/UpdateListingRequest.php b/app/Http/Requests/UpdateListingRequest.php new file mode 100644 index 0000000..a3b58e3 --- /dev/null +++ b/app/Http/Requests/UpdateListingRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Models/Listing.php b/app/Models/Listing.php new file mode 100644 index 0000000..d61b376 --- /dev/null +++ b/app/Models/Listing.php @@ -0,0 +1,12 @@ + */ + use HasFactory; +} diff --git a/app/Policies/ListingPolicy.php b/app/Policies/ListingPolicy.php new file mode 100644 index 0000000..a0c4e43 --- /dev/null +++ b/app/Policies/ListingPolicy.php @@ -0,0 +1,66 @@ + + */ +class ListingFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2025_11_05_094705_create_listings_table.php b/database/migrations/2025_11_05_094705_create_listings_table.php new file mode 100644 index 0000000..e5cf3a5 --- /dev/null +++ b/database/migrations/2025_11_05_094705_create_listings_table.php @@ -0,0 +1,33 @@ +id(); + $table->timestamps(); + $table->text('title')->nullable(false); + $table->text('description')->nullable(false); + $table->text('location')->nullable(false); + $table->decimal('price')->default(0.0); + $table->foreignIdFor(User::class)->nullable(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('listings'); + } +}; diff --git a/database/seeders/ListingSeeder.php b/database/seeders/ListingSeeder.php new file mode 100644 index 0000000..0ae1bf7 --- /dev/null +++ b/database/seeders/ListingSeeder.php @@ -0,0 +1,17 @@ +user(); })->middleware('auth:sanctum'); + +Route::resource('/listing', ListingController::class);