mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
fix columns
This commit is contained in:
@@ -8,6 +8,17 @@ class Form extends \Filament\Forms\Form
|
||||
|
||||
protected $model;
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
if (! $this->hasWrapper) {
|
||||
return collect(parent::getSchema())
|
||||
->first()
|
||||
->getColumns();
|
||||
}
|
||||
|
||||
return $this->columns;
|
||||
}
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model ?? $this->getParent()->getModel();
|
||||
|
||||
@@ -22,6 +22,16 @@ class ListRecords extends Page
|
||||
|
||||
public static $view = 'filament::resources.pages.list-records';
|
||||
|
||||
public function canCreate()
|
||||
{
|
||||
return Filament::can('create', static::getModel());
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canDeleteSelected()
|
||||
{
|
||||
return static::getModel()::find($this->selected)
|
||||
|
||||
@@ -20,11 +20,11 @@ class AttachRecord extends Component
|
||||
|
||||
public function attach($another = false)
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$manager = $this->manager;
|
||||
|
||||
$this->validate();
|
||||
|
||||
$this->getOwner()->{$this->getRelationshipName()}()->attach($this->getRelated());
|
||||
$this->owner->{$this->getRelationshipName()}()->attach($this->related);
|
||||
|
||||
$this->emit('refreshRelationManagerList', $manager);
|
||||
|
||||
@@ -45,7 +45,7 @@ class AttachRecord extends Component
|
||||
->label((string) Str::of($this->getRelationshipName())->singular()->ucfirst())
|
||||
->placeholder('filament::resources/relation-manager.modals.attach.form.related.placeholder')
|
||||
->getOptionSearchResultsUsing(function ($search) {
|
||||
$relationship = $this->getOwner()->{$this->getRelationshipName()}();
|
||||
$relationship = $this->owner->{$this->getRelationshipName()}();
|
||||
|
||||
$query = $relationship->getRelated();
|
||||
|
||||
@@ -57,7 +57,7 @@ class AttachRecord extends Component
|
||||
return $query
|
||||
->where($this->getPrimaryColumn(), $searchOperator, "%{$search}%")
|
||||
->whereDoesntHave($this->getInverseRelationshipName(), function ($query) {
|
||||
$query->where($this->getOwner()->getQualifiedKeyName(), $this->getOwner()->getKey());
|
||||
$query->where($this->owner->getQualifiedKeyName(), $this->owner->getKey());
|
||||
})
|
||||
->pluck($this->getPrimaryColumn(), $query->getKeyName())
|
||||
->toArray();
|
||||
@@ -68,13 +68,13 @@ class AttachRecord extends Component
|
||||
|
||||
public function getInverseRelationshipName()
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$manager = $this->manager;
|
||||
|
||||
if (property_exists($manager, 'inverseRelationship')) {
|
||||
return $manager::$inverseRelationship;
|
||||
}
|
||||
|
||||
return (string) Str::of(class_basename($this->getOwner()))
|
||||
return (string) Str::of(class_basename($this->owner))
|
||||
->lower()
|
||||
->plural()
|
||||
->camel();
|
||||
@@ -82,36 +82,21 @@ class AttachRecord extends Component
|
||||
|
||||
public function getPrimaryColumn()
|
||||
{
|
||||
return $this->getManager()::getPrimaryColumn() ?? $this->getOwner()->getKeyName();
|
||||
return $this->manager::getPrimaryColumn() ?? $this->owner->getKeyName();
|
||||
}
|
||||
|
||||
public function getRelationship()
|
||||
{
|
||||
return $this->getOwner()->{$this->getRelationshipName()}();
|
||||
return $this->owner->{$this->getRelationshipName()}();
|
||||
}
|
||||
|
||||
public function getRelationshipName()
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$manager = $this->manager;
|
||||
|
||||
return $manager::$relationship;
|
||||
}
|
||||
|
||||
public function getOwner()
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function getManager()
|
||||
{
|
||||
return $this->manager;
|
||||
}
|
||||
|
||||
public function getRelated()
|
||||
{
|
||||
return $this->related;
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->fillWithFormDefaults();
|
||||
|
||||
@@ -20,7 +20,7 @@ class CreateRecord extends Component
|
||||
|
||||
public function create($another = false)
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$manager = $this->manager;
|
||||
|
||||
$this->validateTemporaryUploadedFiles();
|
||||
|
||||
@@ -28,7 +28,7 @@ class CreateRecord extends Component
|
||||
|
||||
$this->validate();
|
||||
|
||||
$this->getOwner()->{$this->getRelationshipName()}()->create($this->record);
|
||||
$this->owner->{$this->getRelationshipName()}()->create($this->record);
|
||||
|
||||
$this->emit('refreshRelationManagerList', $manager);
|
||||
|
||||
@@ -44,29 +44,14 @@ class CreateRecord extends Component
|
||||
|
||||
protected function form(Form $form)
|
||||
{
|
||||
return $this->getManager()::form(
|
||||
$form->model(get_class($this->getOwner()->{$this->getRelationshipName()}()->getModel())),
|
||||
return $this->manager::form(
|
||||
$form->model(get_class($this->owner->{$this->getRelationshipName()}()->getModel())),
|
||||
);
|
||||
}
|
||||
|
||||
public function getManager()
|
||||
{
|
||||
return $this->manager;
|
||||
}
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function getOwner()
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function getRelationshipName()
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$manager = $this->manager;
|
||||
|
||||
return $manager::$relationship;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class EditRecord extends Component
|
||||
|
||||
protected function form(Form $form)
|
||||
{
|
||||
return $this->getManager()::form($form->model(get_class($this->getOwner()->{$this->getRelationshipName()}()->getModel())));
|
||||
return $this->manager::form($form->model(get_class($this->owner->{$this->getRelationshipName()}()->getModel())));
|
||||
}
|
||||
|
||||
public function getQuery()
|
||||
@@ -34,22 +34,12 @@ class EditRecord extends Component
|
||||
|
||||
public function getRelationship()
|
||||
{
|
||||
return $this->getOwner()->{$this->getRelationshipName()}();
|
||||
}
|
||||
|
||||
public function getManager()
|
||||
{
|
||||
return $this->manager;
|
||||
}
|
||||
|
||||
public function getOwner()
|
||||
{
|
||||
return $this->owner;
|
||||
return $this->owner->{$this->getRelationshipName()}();
|
||||
}
|
||||
|
||||
public function getRelationshipName()
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$manager = $this->manager;
|
||||
|
||||
return $manager::$relationship;
|
||||
}
|
||||
@@ -66,7 +56,7 @@ class EditRecord extends Component
|
||||
|
||||
public function save()
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$manager = $this->manager;
|
||||
|
||||
abort_unless(Filament::can('update', $this->record), 403);
|
||||
|
||||
@@ -88,7 +78,7 @@ class EditRecord extends Component
|
||||
|
||||
public function switchRecord($manager, $record)
|
||||
{
|
||||
if ($manager !== $this->getManager()) {
|
||||
if ($manager !== $this->manager) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,29 +30,9 @@ class ListRecords extends Component
|
||||
'refreshRelationManagerList' => 'refreshList',
|
||||
];
|
||||
|
||||
public function canAttach()
|
||||
{
|
||||
return $this->canAttach;
|
||||
}
|
||||
|
||||
public function canCreate()
|
||||
{
|
||||
return $this->canCreate;
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
return $this->canDelete;
|
||||
}
|
||||
|
||||
public function canDetach()
|
||||
{
|
||||
return $this->canDetach;
|
||||
}
|
||||
|
||||
public function canDeleteSelected()
|
||||
{
|
||||
return $this->getModel()::find($this->selected)
|
||||
return $this->model::find($this->selected)
|
||||
->contains(function ($record) {
|
||||
return Filament::can('delete', $record);
|
||||
});
|
||||
@@ -60,10 +40,10 @@ class ListRecords extends Component
|
||||
|
||||
public function deleteSelected()
|
||||
{
|
||||
abort_unless($this->canDelete(), 403);
|
||||
abort_unless($this->canDelete, 403);
|
||||
|
||||
$this->getModel()::destroy(
|
||||
$this->getModel()::find($this->selected)
|
||||
$this->model::destroy(
|
||||
$this->model::find($this->selected)
|
||||
->filter(function ($record) {
|
||||
return Filament::can('delete', $record);
|
||||
})
|
||||
@@ -76,39 +56,26 @@ class ListRecords extends Component
|
||||
|
||||
public function detachSelected()
|
||||
{
|
||||
$manager = $this->manager;
|
||||
|
||||
$relationship = $this->getRelationship();
|
||||
|
||||
$relationship->detach($this->selected);
|
||||
|
||||
$this->dispatchBrowserEvent('close', $this->getManager() . 'RelationManagerDetachModal');
|
||||
$this->dispatchBrowserEvent('notify', __($this->getManager()::$detachModalDetachedMessage));
|
||||
$this->dispatchBrowserEvent('close', $manager . 'RelationManagerDetachModal');
|
||||
$this->dispatchBrowserEvent('notify', __($manager::$detachModalDetachedMessage));
|
||||
|
||||
$this->selected = [];
|
||||
}
|
||||
|
||||
public function getManager()
|
||||
{
|
||||
return $this->manager;
|
||||
}
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function getOwner()
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function getRelationship()
|
||||
{
|
||||
return $this->getOwner()->{$this->getRelationshipName()}();
|
||||
return $this->owner->{$this->getRelationshipName()}();
|
||||
}
|
||||
|
||||
public function getRelationshipName()
|
||||
{
|
||||
return $this->getManager()::getRelationshipName();
|
||||
return $this->manager::getRelationshipName();
|
||||
}
|
||||
|
||||
public function getPrimaryColumnAction($record)
|
||||
@@ -127,7 +94,7 @@ class ListRecords extends Component
|
||||
|
||||
public function getRecordActions()
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$manager = $this->manager;
|
||||
|
||||
return [
|
||||
RecordActions\Link::make('edit')
|
||||
@@ -144,7 +111,7 @@ class ListRecords extends Component
|
||||
|
||||
protected function table(Table $table)
|
||||
{
|
||||
return $this->getManager()::table(
|
||||
return $this->manager::table(
|
||||
$table
|
||||
->primaryColumnAction(function ($record) {
|
||||
return $this->getPrimaryColumnAction($record);
|
||||
@@ -155,29 +122,29 @@ class ListRecords extends Component
|
||||
|
||||
public function openAttach()
|
||||
{
|
||||
$this->dispatchBrowserEvent('open', $this->getManager() . 'RelationManagerAttachModal');
|
||||
$this->dispatchBrowserEvent('open', $this->manager . 'RelationManagerAttachModal');
|
||||
}
|
||||
|
||||
public function openCreate()
|
||||
{
|
||||
$this->dispatchBrowserEvent('open', $this->getManager() . 'RelationManagerCreateModal');
|
||||
$this->dispatchBrowserEvent('open', $this->manager . 'RelationManagerCreateModal');
|
||||
}
|
||||
|
||||
public function openDetach()
|
||||
{
|
||||
$this->dispatchBrowserEvent('open', $this->getManager() . 'RelationManagerDetachModal');
|
||||
$this->dispatchBrowserEvent('open', $this->manager . 'RelationManagerDetachModal');
|
||||
}
|
||||
|
||||
public function openEdit($record)
|
||||
{
|
||||
$this->emit('switchRelationManagerEditRecord', $this->getManager(), $record);
|
||||
$this->emit('switchRelationManagerEditRecord', $this->manager, $record);
|
||||
|
||||
$this->dispatchBrowserEvent('open', $this->getManager() . 'RelationManagerEditModal');
|
||||
$this->dispatchBrowserEvent('open', $this->manager . 'RelationManagerEditModal');
|
||||
}
|
||||
|
||||
public function refreshList($manager = null)
|
||||
{
|
||||
if ($manager !== null && $manager !== $this->getManager()) {
|
||||
if ($manager !== null && $manager !== $this->manager) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user