xtremer360
8 months ago

Interfaces and Parent Controllers

Posted 8 months ago by xtremer360

I have the following files and wondered if anyone had any suggestions on what to do because I have a test that isn't passing but I need to make sure that I am doing the right thing to get this to work.

Currently my error is this.

ErrorException: Declaration of App\Http\Controllers\ResourceOneSuspensionsController::store(App\Model, $model) should be compatible with App\Http\Controllers\Suspensi
onsController::store($suspendee)
\App\Controllers\SuspensionsController
\App\Controllers\ResourceOneSuspensionsController
\App\Controllers\ResourceTwoSuspensionsController
\App\Controllers\ResourceThreeSuspensionsController
\App\Controllers\ResourceFourSuspensionsController
<?php

namespace App\Http\Controllers;

use App\Interfaces\Suspendable;

class SuspensionsController extends Controller
{
    /**
     * Suspend a model.
     *
     * @param  \App\Interfaces\Suspendable  $suspendee
     * @return \lluminate\Http\RedirectResponse
     */
    public function store($suspendee)
    {
        $this->authorize('suspend', $suspendee);

        abort_if($suspendee->isSuspended(), 403);

        $suspendee->suspend();

        $route = Str::plural($suspendee->getRouteKeyName());

        return redirect()->route("{$route}.index", ['state' => 'suspended']);
    }
}
<?php

namespace App\Http\Controllers;

use App\ResourceOneModel;

class ResourceOneSuspensionsController extends SuspensionsController
{
    public function store(ResourceOneModel $model)
    {
        return parent::store($model);
    }

    public function destroy(ResourceOneModel $model)
    {
        return parent::destroy($model);
    }
}

Please sign in or create an account to participate in this conversation.