File "CrupdateWorkspaceRequest.php"

Full Path: /var/www/drive/foundation/src/Workspaces/Requests/CrupdateWorkspaceRequest.php
File size: 790 bytes
MIME-type: text/x-php
Charset: utf-8

<?php

namespace Common\Workspaces\Requests;

use Auth;
use Common\Core\BaseFormRequest;
use Illuminate\Validation\Rule;

class CrupdateWorkspaceRequest extends BaseFormRequest
{
    public function rules(): array
    {
        $required = $this->getMethod() === 'POST' ? 'required' : '';
        $ignore =
            $this->getMethod() === 'PUT' ? $this->route('workspace')->id : '';
        $userId = $this->route('workspace')
            ? $this->route('workspace')->user_id
            : Auth::id();

        return [
            'name' => [
                $required,
                'string',
                'min:3',
                Rule::unique('workspaces')
                    ->where('owner_id', $userId)
                    ->ignore($ignore),
            ],
        ];
    }
}