Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/job-board.corals.io/Corals/modules/Classified/Http/Requests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/job-board.corals.io/Corals/modules/Classified/Http/Requests/ProductRequest.php
<?php

namespace Corals\Modules\Classified\Http\Requests;

use Corals\Foundation\Http\Requests\BaseRequest;
use Corals\Modules\Classified\Models\Product;
use Corals\Modules\Utility\Models\Category\Category;

class ProductRequest extends BaseRequest
{
    public $categoryAttributes = [];

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $this->setModel(Product::class);
        return $this->isAuthorized();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $this->setModel(Product::class);
        $rules = parent::rules();

        if ($this->isUpdate() || $this->isStore()) {
            $rules = array_merge($rules, [
                'name' => 'required|max:191',
                'caption' => 'required',
                'status' => 'required',
                'categories' => 'required',
                'price' => 'required_without:price_on_call',
                'price_on_call' => 'required_without:price',
            ]);


            if (\Settings::get('classified_enable_google_location', false)) {
                $rules = array_merge($rules, ['address' => 'required']);
            } else {
                $rules = array_merge($rules, ['location_id' => 'required']);
            }


            $categories = $this->get('categories', []);

            $categories = Category::query()->whereIn('id', $categories)->get();

            $attributes = collect([]);

            foreach ($categories as $category) {
                $attributes = $attributes->merge($category->categoryAttributes);
            }
            $this->categoryAttributes = $attributes;

            foreach ($attributes as $attribute) {
                if ($attribute->required) {
                    $rules = array_merge($rules, [
                        "options." . $attribute->id => 'required',
                    ]);
                }
            }

        }

        if ($this->isStore()) {

            $rules = array_merge($rules, [
                'slug' => 'max:191|unique:classified_products,slug'
            ]);
            $rules = array_merge($rules, []);
        }

        if ($this->isUpdate()) {
            $product = $this->route('product');

            $rules = array_merge($rules, [
                'slug' => 'max:191|unique:classified_products,slug,' . $product->id,
            ]);
            $rules = array_merge($rules, []);
        }


        return $rules;
    }

    public function attributes()
    {
        $attributes = [
        ];

        if ($this->isUpdate() || $this->isStore()) {
            $options = $this->categoryAttributes;

            foreach ($options as $option) {
                $attributes = array_merge($attributes, [
                    "options.$option->id" => $option->label,
                ]);
            }
        }

        return $attributes;
    }

}

Spamworldpro Mini