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/mcoil.corals.io/app/Http/Controllers/Admin/Attributes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mcoil.corals.io/app/Http/Controllers/Admin/Attributes/AttributeValueController.php
<?php

namespace App\Http\Controllers\Admin\Attributes;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Shop\Attributes\Repositories\AttributeRepositoryInterface;
use App\Shop\AttributeValues\AttributeValue;
use App\Shop\Attributes\Attribute;
use App\Shop\AttributeValues\Repositories\AttributeValueRepository;
use App\Shop\AttributeValues\Repositories\AttributeValueRepositoryInterface;
use App\Shop\AttributeValues\Requests\CreateAttributeValueRequest;

class AttributeValueController extends Controller {
    /**
     * @var AttributeRepositoryInterface
     */
    private $attributeRepo;

    /**
     * @var AttributeValueRepositoryInterface
     */
    private $attributeValueRepo;

    /**
     * AttributeValueController constructor.
     * @param AttributeRepositoryInterface $attributeRepository
     * @param AttributeValueRepositoryInterface $attributeValueRepository
     */
    public function __construct(
        AttributeRepositoryInterface $attributeRepository,
        AttributeValueRepositoryInterface $attributeValueRepository
    ) {
        $this->attributeRepo = $attributeRepository;
        $this->attributeValueRepo = $attributeValueRepository;
    }

    public function create($id) {
        return view('admin.attribute-values.create', [
            'attribute' => $this->attributeRepo->findAttributeById($id)
        ]);
    }

    public function edit($id)
    {
    	// Fetch the attribute values details
    	$attributeValue = AttributeValue::find($id);

    	// Fetch attribute details
    	$attribute = Attribute::find($attributeValue->attribute_id);

    	return view('admin.attribute-values.edit', ['attributeValue' => $attributeValue, 'attribute' => $attribute]);
    }

    public function update(CreateAttributeValueRequest $request, $id)
    {
    	$attributeValue = AttributeValue::where('id', $id)->first();
    	$attributeValue->value = $request->value;
    	
    	if($attributeValue->save())
    	{
        	return redirect()->route('admin.attributes.value.edit', $attributeValue->id)->with('message', 'Attribute value update successfully.');
    	}
    	else
    	{
    		return redirect()->route('admin.attributes.value.edit', $attributeValue->id)->with('error', 'Attribute value does not updated due to some error.');
    	}
    }

    /**
     * @param CreateAttributeValueRequest $request
     * @param $id
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(CreateAttributeValueRequest $request, $id) {
        $attribute = $this->attributeRepo->findAttributeById($id);
        $attributeValue = new AttributeValue($request->except('_token'));
        $attributeValueRepo = new AttributeValueRepository($attributeValue);
        $attributeValueRepo->associateToAttribute($attribute);
        return redirect()->route('admin.attributes.show', $attribute->id)->with('message', 'Attribute value created successfully.');
    }

    /**
     * @param $attributeId
     * @param $attributeValueId
     * @return \Illuminate\Http\RedirectResponse
     */
    public function destroy(Request $request, $attributeId, $attributeValueId) {
        $attributeId = $request->id;
        $attributeValueId = $request->itemid;
        $attributeValue = $this->attributeValueRepo->findOneOrFail($attributeValueId);
        $attributeValueRepo = new AttributeValueRepository($attributeValue);
        $attributeValueRepo->dissociateFromAttribute();
        return redirect()->back();
    }
}

Spamworldpro Mini