Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
marchershey committed May 25, 2024
1 parent 6e5a49b commit 74106a4
Show file tree
Hide file tree
Showing 15 changed files with 400 additions and 77 deletions.
20 changes: 0 additions & 20 deletions app/app/Http/Pages/Host/Properties/AddProperty.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Pages\Host\Properties\NewProperty;

use App\Models\Property;
use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('layouts.minimal', ['title' => 'The Basics'])]
class NewPropertyBasics extends Component
{
public $property;
public $fees = [];
public $amenities = [];

public function render()
{
return view('pages.host.properties.new-property.new-property-basics');
}

public function mount(Property $property)
{
$this->property = $property;
}

public function load()
{
//
}

public function end()
{
//
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Pages\Host\Properties\NewProperty;

use App\Models\Property;
use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('layouts.minimal', ['title' => 'Add a new property'])]
class NewPropertyOverview extends Component
{
public function render()
{
return view('pages.host.properties.new-property.new-property-overview');
}

public function start()
{
$property = Property::startNewProperty();

$this->redirect(route('host.properties.new-property.basics', $property), navigate: true);
}
}
46 changes: 39 additions & 7 deletions app/app/Models/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;

class Property extends Model
{
Expand All @@ -18,29 +19,60 @@ public static function boot()
parent::boot();

static::creating(function ($property) {
// Create a slug for the property

/**
* Create the slug based off of the property name
* ! No longer works due to creating model before having property name.
* TODO: Need to figure out a way to do this after property has been created
*/
$property->slug = self::generateSlug($property->name);
});
}

public static function generateSlug($property_name)
/**
* Get the photos for the property.
*/
public function photos(): HasMany
{
return $this->hasMany(PropertyPhoto::class)->orderBy('order');
}



/**
* Generate a slug based off of the Property's name
*
* @param string $property_name
* @return string
*/
public static function generateSlug(string $property_name): string
{
$slug = \Illuminate\Support\Str::slug($property_name);
$slug = Str::slug($property_name);
$newSlug = $slug;

$n = 1;
while (\App\Models\Property::whereSlug($newSlug)->exists()) {
$newSlug = \Illuminate\Support\Str::slug($slug . '-' . $n++);
$newSlug = Str::slug($slug . '-' . $n++);
}

return $newSlug;
}


/**
* Get the photos for the property.
* Return a new or existing property
*
* To prevent a bunch of empty properties in the database, this function checks
* if a property exists in the database that is in progress but doesn't have a name.
* If a property is in progress but has a name, it will be displayed on the property
* index, so no need to return it.
*
* @return Property
*/
public function photos(): HasMany
public static function startNewProperty(): Property
{
return $this->hasMany(PropertyPhoto::class)->orderBy('order');
$property = self::where('in_progress', true)->where('name', null)->first();

return ($property) ? $property : self::create();
}
}
1 change: 1 addition & 0 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"usernotnull/tall-toasts": "v2.1.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.13",
"fakerphp/faker": "v1.23.1",
"laravel/pint": "v1.15.3",
"laravel/sail": "v1.29.1",
Expand Down
154 changes: 153 additions & 1 deletion app/composer.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ public function up(): void
{
Schema::create('properties', function (Blueprint $table) {
$table->id()->from(1000);
$table->string('name');
$table->string('address_street');
$table->string('address_city');
$table->string('address_state');
$table->integer('address_zip');
$table->string('property_headline');
$table->text('property_description');
$table->integer('guest_count');
$table->integer('bed_count');
$table->integer('bedroom_count');
$table->decimal('bathroom_count', 4, 1);
$table->string('rate');
$table->string('tax_rate');
$table->string('calendar_color');
$table->integer('min_nights');
$table->boolean('active')->default(true);
$table->integer('host_id');
$table->string('slug');
$table->string('name')->nullable();
$table->string('address_street')->nullable();
$table->string('address_city')->nullable();
$table->string('address_state')->nullable();
$table->integer('address_zip')->nullable();
$table->string('property_headline')->nullable();
$table->text('property_description')->nullable();
$table->integer('guest_count')->nullable();
$table->integer('bed_count')->nullable();
$table->integer('bedroom_count')->nullable();
$table->decimal('bathroom_count', 4, 1)->nullable();
$table->string('rate')->nullable();
$table->string('tax_rate')->nullable();
$table->string('calendar_color')->nullable();
$table->integer('min_nights')->nullable();
$table->boolean('active')->default(true)->nullable();
$table->integer('host_id')->nullable();
$table->string('slug')->nullable();
$table->boolean('in_progress')->default(true);
// $table->integer('type_id');
$table->timestamps();
$table->softDeletes();
Expand Down
Loading

0 comments on commit 74106a4

Please sign in to comment.