mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
AttachLibraryItemToLibrary
This commit is contained in:
51
app/Nova/Actions/AttachLibraryItemToLibrary.php
Normal file
51
app/Nova/Actions/AttachLibraryItemToLibrary.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Nova\Actions;
|
||||||
|
|
||||||
|
use App\Models\Library;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Laravel\Nova\Actions\Action;
|
||||||
|
use Laravel\Nova\Fields\ActionFields;
|
||||||
|
use Laravel\Nova\Fields\Select;
|
||||||
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||||
|
|
||||||
|
class AttachLibraryItemToLibrary extends Action
|
||||||
|
{
|
||||||
|
use InteractsWithQueue, Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the action on the given models.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Fields\ActionFields $fields
|
||||||
|
* @param \Illuminate\Support\Collection $models
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle(ActionFields $fields, Collection $models)
|
||||||
|
{
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$model->libraries()
|
||||||
|
->attach($fields->library);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the fields available on the action.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function fields(NovaRequest $request)
|
||||||
|
{
|
||||||
|
$libraries = Library::query()
|
||||||
|
->pluck('name', 'id');
|
||||||
|
|
||||||
|
return [
|
||||||
|
Select::make('Library')
|
||||||
|
->options($libraries),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace App\Nova;
|
|||||||
|
|
||||||
use App\Enums\LibraryItemType;
|
use App\Enums\LibraryItemType;
|
||||||
use App\Notifications\ModelCreatedNotification;
|
use App\Notifications\ModelCreatedNotification;
|
||||||
|
use App\Nova\Actions\AttachLibraryItemToLibrary;
|
||||||
use App\Nova\Actions\SetStatusAction;
|
use App\Nova\Actions\SetStatusAction;
|
||||||
use App\Nova\Filters\LibraryItemWithoutLibrary;
|
use App\Nova\Filters\LibraryItemWithoutLibrary;
|
||||||
use Ebess\AdvancedNovaMediaLibrary\Fields\Files;
|
use Ebess\AdvancedNovaMediaLibrary\Fields\Files;
|
||||||
@@ -225,6 +226,7 @@ class LibraryItem extends Resource
|
|||||||
public function actions(Request $request)
|
public function actions(Request $request)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
new AttachLibraryItemToLibrary(),
|
||||||
new SetStatusAction(),
|
new SetStatusAction(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user