JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr{ gilour

File "BiolinkWidgetsController.php"

Full Path: /home/markqprx/iniasli.pro/app/Http/Controllers/BiolinkWidgetsController.php
File size: 1.16 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Http\Controllers;

use App\Models\Biolink;
use App\Models\BiolinkWidget;
use Common\Core\BaseController;

class BiolinkWidgetsController extends BaseController
{
    public function store(Biolink $biolink)
    {
        $this->authorize('update', $biolink);

        $payload = $this->validate(request(), [
            'type' => 'required|string',
            'position' => 'int',
            'config' => 'nullable|array',
        ]);

        $widget = $biolink->widgets()->create($payload);

        $biolink->adjustPositions(
            direction: 'increment',
            anchor: $payload['position'] ?? null,
            widgetToSkip: $widget->id,
        );

        return $this->success([
            'biolink' => $biolink->fresh()->loadContent(),
        ]);
    }

    public function update(Biolink $biolink, BiolinkWidget $widget)
    {
        $this->authorize('update', $biolink);

        $payload = $this->validate(request(), [
            'type' => 'string',
            'config' => 'array',
        ]);

        $widget->update($payload);

        return $this->success([
            'biolink' => $biolink->fresh()->loadContent(),
        ]);
    }
}