HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/file.nepi.ir/common/Channels/CrupdateChannel.php
<?php

namespace Common\Channels;

use App\Channel;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class CrupdateChannel
{
    public function execute($params, $initialChannel = null): Channel
    {
        if (!$initialChannel) {
            $channel = app(Channel::class)->newInstance([
                'user_id' => Auth::id(),
            ]);
        } else {
            $channel = $initialChannel;
        }

        $attributes = [
            'name' => $params['name'],
            'tagline' => Arr::get($params, 'tagline'),
            'slug' => Arr::get($params, 'slug') ?? slugify($params['name']),
            // merge old config so config that is not in crupdate channel form is not lost
            'config' => array_merge(
                $initialChannel['config'] ?? [],
                $params['config'],
            ),
        ];

        $channel
            ->fill(
                array_merge($attributes, [
                    // make sure updated_at is always changed, event if model is
                    // not dirty otherwise channel cache will not be cleared
                    'updated_at' => now(),
                ]),
            )
            ->save();

        if (
            $channel->config['contentType'] === 'manual' &&
            ($channelContent = Arr::get($params, 'content.data'))
        ) {
            // detach old channelables
            DB::table('channelables')
                ->where('channel_id', $channel->id)
                ->delete();

            $pivots = collect($channelContent)
                ->map(function ($item, $i) use ($channel) {
                    return [
                        'channel_id' => $channel->id,
                        'channelable_id' => $item['id'],
                        'channelable_type' => modelTypeToNamespace(
                            $item['model_type'],
                        ),
                        'order' => $i,
                    ];
                })
                ->filter(function ($item) use ($channel) {
                    // channels should not be attached to themselves
                    return $item['channelable_type'] !== Channel::class ||
                        $item['channelable_id'] !== $channel->id;
                });
            DB::table('channelables')->insert($pivots->toArray());
        }

        return $channel;
    }
}