%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/diaspora/api_internal/app/Http/Controllers/Api/v1/
Upload File :
Create Path :
Current File : /var/www/html/diaspora/api_internal/app/Http/Controllers/Api/v1/CountrySectionsController.php

<?php

namespace App\Http\Controllers\Api\v1;

use App\Http\Controllers\Api\ApiController;
use App\Http\Requests\Api\v1\Countries\CreateSectionRequest;
use App\Models\Country;
use App\Models\Section;
use App\Transformers\SectionTransformer;
use Carbon\Carbon;
use Illuminate\Http\Request;

class CountrySectionsController extends ApiController
{
    /**
     * User $user.
     */
    protected $user;

    /**
     * PostsController constructor.
     */
    public function __construct()
    {
        $this->user = auth()
            ->guard('api')
            ->user();
    }

    public function index(Request $request, Country $country)
    {
        return $this->collection($country->sections, new SectionTransformer());
    }

    /**
     * @param Country $country
     * @param Section $section
     * @return CountriesController
     */
    public function show(Country $country, Section $section)
    {
        return $this->item($section, new SectionTransformer());
    }

    public function store(CreateSectionRequest $request, Country $country)
    {
        $count = $country->sections()
                         ->count();
        /** @var Section $section */
        $section = $country->sections()
                           ->make($request->all());

        $section->order = $count + 1;
        $section->save();
        activity()
            ->causedBy($this->user)
            ->performedOn($section)
            ->log('created');
        return $this->item($section, new SectionTransformer());
    }

    public function update(CreateSectionRequest $request, Country $country, Section $section)
    {
        $section->update($request->except('order'));
        $section->updated_at = Carbon::now();
        $section->save();
        activity()
            ->causedBy($this->user)
            ->performedOn($section)
            ->log('updated');
        return $this->item($section, new SectionTransformer());
    }

    public function makeVisible(Country $country, Section $section)
    {
        $section->show();
        activity()
            ->causedBy($this->user)
            ->performedOn($section)
            ->log('enabled');
        return $this->item($section, new SectionTransformer());
    }

    public function makeInvisible(Country $country, Section $section)
    {
        $section->hide();
        activity()
            ->causedBy($this->user)
            ->performedOn($section)
            ->log('disabled');
        return $this->item($section, new SectionTransformer());
    }

    public function moveUp(Country $country, Section $section)
    {
        $section->moveUp();
        activity()
            ->causedBy($this->user)
            ->performedOn($section)
            ->log('reordered');
        return $this->collection($country->sections, new SectionTransformer());
    }

    public function moveDown(Country $country, Section $section)
    {
        $section->moveDown();
        activity()
            ->causedBy($this->user)
            ->performedOn($section)
            ->log('reordered');
        return $this->collection($country->sections, new SectionTransformer());
    }

}

Zerion Mini Shell 1.0