-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from plank/1-navigation-model
Add base model linking functionality
- Loading branch information
Showing
30 changed files
with
691 additions
and
53 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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* You can place your custom package configuration in here. | ||
*/ | ||
return [ | ||
use Plank\Frontdesk\Models\Hyperlink; | ||
use Plank\Frontdesk\Models\Menu; | ||
use Plank\Frontdesk\Tests\Database\Factories\HyperlinkFactory; | ||
use Plank\Frontdesk\Tests\Database\Factories\MenuFactory; | ||
|
||
return [ | ||
'models' => [ | ||
'hyperlink' => Hyperlink::class, | ||
'menu' => Menu::class | ||
], | ||
'factories' => [ | ||
'hyperlink' => HyperlinkFactory::class, | ||
'menu' => MenuFactory::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,38 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
public function up() | ||
{ | ||
Schema::create('hyperlinks', function (Blueprint $table) { | ||
$table->id(); | ||
$table->unsignedBigInteger('parent_id')->nullable(); | ||
$table->morphs('linkable'); | ||
$table->foreignId('menu_id') | ||
->nullable() | ||
->references('id') | ||
->on('menus'); | ||
$table->string('title'); | ||
$table->unsignedInteger('order')->nullable(); | ||
$table->string('destination')->nullable(); // if this is null the link isn't clickable | ||
$table->timestamps(); | ||
}); | ||
|
||
Schema::table('hyperlinks', function (Blueprint $table) { | ||
$table->foreign('parent_id') | ||
->references("id") | ||
->on('hyperlinks'); | ||
// make the morph nullable in-case we want to link externally | ||
$table->string('linkable_type')->nullable()->change(); | ||
$table->unsignedBigInteger('linkable_id')->nullable()->change(); | ||
}); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::dropIfExists('hyperlinks'); | ||
} | ||
}; |
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 | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('menuables', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('menu_id')->references('id')->on('menus'); | ||
$table->morphs('menuable'); | ||
$table->integer('order')->nullable(); | ||
}); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::dropIfExists('menuables'); | ||
} | ||
}; |
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,22 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('menus', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('identifier'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::dropIfExists('menus'); | ||
} | ||
}; |
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,23 @@ | ||
<?php | ||
|
||
namespace Plank\Frontdesk\Concerns; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\MorphToMany; | ||
use Plank\Frontdesk\Models\Menu; | ||
/** | ||
* @mixin \Illuminate\Database\Eloquent\Model | ||
* | ||
* @property-read Collection<Menu> $menus | ||
*/ | ||
trait HasMenus | ||
{ | ||
/** | ||
* @return MorphToMany | ||
*/ | ||
public function menus(): MorphToMany | ||
{ | ||
return $this->morphToMany(Menu::class, 'menuable') | ||
->orderByPivot('order'); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace Plank\Frontdesk\Concerns; | ||
|
||
use Illuminate\Database\Eloquent\Relations\MorphMany; | ||
use Plank\Frontdesk\Models\Hyperlink; | ||
|
||
/** | ||
* @mixin \Illuminate\Database\Eloquent\Model | ||
* | ||
* @property-read \Illuminate\Database\Eloquent\Collection<Hyperlink> $hyperlinks | ||
*/ | ||
trait IsLinkable | ||
{ | ||
public function hyperlinks(): MorphMany | ||
{ | ||
return $this->morphMany(Hyperlink::class, 'linkable'); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Plank\Frontdesk\Contracts; | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
/** | ||
* @property-read Collection<Model&LinksToContent> $hyperlinks | ||
* Could add $navs to this interface if you decide to implement it | ||
*/ | ||
interface AggregatesLinks | ||
{ | ||
public function hyperlinks(): HasMany; | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Plank\Frontdesk\Contracts; | ||
|
||
use Illuminate\Database\Eloquent\Casts\Attribute; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\MorphMany; | ||
/** | ||
* @property-read Collection<Model&LinksToContent> $hyperlinks | ||
* @property-read string $linkTitle | ||
* @property-read string $linkUrl | ||
*/ | ||
interface Linkable | ||
{ | ||
public function hyperlinks(): MorphMany; | ||
|
||
public function linkTitle(): Attribute; | ||
|
||
public function linkUrl(): Attribute; | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Plank\Frontdesk\Contracts; | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
use Illuminate\Database\Eloquent\Relations\MorphTo; | ||
use Plank\Frontdesk\Models\Menu; | ||
|
||
/** | ||
* @property int|string $id | ||
* @property int|string $parent_id | ||
* @property string $title | ||
* @property string $destination | ||
* @property-read Collection<Linkable> $linkable | ||
* @property-read Collection<Menu> $menu | ||
* @property-read Model&LinksToContent|null $parent | ||
* @property-read Collection<Model&LinksToContent> $children | ||
*/ | ||
interface LinksToContent | ||
{ | ||
public function linkable(): MorphTo; | ||
|
||
public function menu(): BelongsTo; | ||
|
||
public function parent(): BelongsTo; | ||
|
||
public function children(): HasMany; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace Plank\Frontdesk\Contracts; | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\MorphToMany; | ||
|
||
|
||
/** | ||
* @property-read Collection<Model&AggregatesLinks> $menus | ||
* Could add $navs to this interface if you decide to implement it | ||
*/ | ||
interface Menuable | ||
{ | ||
public function menus(): MorphToMany; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.