-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
387 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Category extends Model | ||
{ | ||
use HasFactory; | ||
|
||
/** | ||
* Get the building that owns the category. | ||
*/ | ||
public function building() | ||
{ | ||
return $this->belongsTo(Building::class); | ||
} | ||
|
||
/** | ||
* Get the listing associated with the category. | ||
*/ | ||
public function listing() | ||
{ | ||
return $this->hasOne(Listing::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Listing extends Model | ||
{ | ||
use HasFactory; | ||
|
||
/** | ||
* Get the category for the listing. | ||
*/ | ||
public function category() | ||
{ | ||
return $this->belongsTo(Category::class); | ||
} | ||
|
||
/** | ||
* Get the building that owns the listing. | ||
*/ | ||
public function building() | ||
{ | ||
return $this->hasOneThrough(Building::class, Category::class, 'id', 'id', 'category_id', 'building_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace App\Nova; | ||
|
||
use Illuminate\Http\Request; | ||
use Laravel\Nova\Fields\BelongsTo; | ||
use Laravel\Nova\Fields\HasOne; | ||
use Laravel\Nova\Fields\ID; | ||
use Laravel\Nova\Http\Requests\NovaRequest; | ||
|
||
class Category extends Resource | ||
{ | ||
/** | ||
* The model the resource corresponds to. | ||
* | ||
* @var class-string<\App\Models\Category> | ||
*/ | ||
public static $model = \App\Models\Category::class; | ||
|
||
/** | ||
* The single value that should be used to represent the resource when being displayed. | ||
* | ||
* @var string | ||
*/ | ||
public static $title = 'id'; | ||
|
||
/** | ||
* The columns that should be searched. | ||
* | ||
* @var array | ||
*/ | ||
public static $search = [ | ||
'id', | ||
]; | ||
|
||
/** | ||
* Get the fields displayed by the resource. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function fields(NovaRequest $request) | ||
{ | ||
return [ | ||
ID::make()->sortable(), | ||
|
||
BelongsTo::make('Building') | ||
->showWhenPeeking() | ||
->sortable() | ||
->filterable(), | ||
|
||
HasOne::make('Listing') | ||
->hideWhenCreating() | ||
->hideWhenUpdating() | ||
->sortable(), | ||
]; | ||
} | ||
|
||
/** | ||
* Get the cards available for the request. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function cards(NovaRequest $request) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the filters available for the resource. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function filters(NovaRequest $request) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the lenses available for the resource. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function lenses(NovaRequest $request) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the actions available for the resource. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function actions(NovaRequest $request) | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace App\Nova; | ||
|
||
use Illuminate\Http\Request; | ||
use Laravel\Nova\Fields\BelongsTo; | ||
use Laravel\Nova\Fields\HasOneThrough; | ||
use Laravel\Nova\Fields\ID; | ||
use Laravel\Nova\Http\Requests\NovaRequest; | ||
|
||
class Listing extends Resource | ||
{ | ||
/** | ||
* The model the resource corresponds to. | ||
* | ||
* @var class-string<\App\Models\Listing> | ||
*/ | ||
public static $model = \App\Models\Listing::class; | ||
|
||
/** | ||
* The single value that should be used to represent the resource when being displayed. | ||
* | ||
* @var string | ||
*/ | ||
public static $title = 'id'; | ||
|
||
/** | ||
* The columns that should be searched. | ||
* | ||
* @var array | ||
*/ | ||
public static $search = [ | ||
'id', | ||
]; | ||
|
||
/** | ||
* Get the fields displayed by the resource. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function fields(NovaRequest $request) | ||
{ | ||
return [ | ||
ID::make()->sortable(), | ||
|
||
BelongsTo::make('Category') | ||
->showWhenPeeking() | ||
->sortable() | ||
->filterable(), | ||
|
||
HasOneThrough::make('Building') | ||
->sortable() | ||
->exceptOnForms(), | ||
]; | ||
} | ||
|
||
/** | ||
* Get the cards available for the request. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function cards(NovaRequest $request) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the filters available for the resource. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function filters(NovaRequest $request) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the lenses available for the resource. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function lenses(NovaRequest $request) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the actions available for the resource. | ||
* | ||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request | ||
* @return array | ||
*/ | ||
public function actions(NovaRequest $request) | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Category> | ||
*/ | ||
class CategoryFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Listing> | ||
*/ | ||
class ListingFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
database/migrations/2023_01_17_100744_create_categories_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('categories', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('building_id')->constrained(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('categories'); | ||
} | ||
}; |
Oops, something went wrong.