0
votes

I have a function. If I click on this function, the user should be activate or deactivate.

I tried different things, but my code doesnt work.

public function deactivate($id)
    {
        $user = User::find($id);
        if ($user->verified == 1){
            $user->verified = 0;
            $user->save();
            $angebot = Angebot::where('firma', $id);
            $angebot->delete();
            return redirect('/admin')->with('success', 'Nutzer wurde erfolgreich deaktiviert');
        }

        if($user->verified == 0){
            $user->verified = 1;
            $user->save();
            return redirect('/admin')->with('success', 'Nutzer wurde erfolgreich aktiviert');
        }

    }

this is my function in my controller

and this is my view:

<a href="{{ route('admin.deactivate',$user->id)}}"> @if($user->verified === 0)
                            <button class="btn btn-primary"><i class="fas fa-eye-slash"></i></button>
                            @else <button class="btn btn-primary"><i class="fas fa-eye"></i></button>@endif</a>

and this is my route:

Route::get('admin/{id}', 'AdminController@deactivate')->name('admin.deactivate');

this are my other routes:

Route::resource('admin', 'AdminController');

if i do php artisan route:list i got this

Domain | Method | URI | Name | Action | Middleware | +--------+-----------+----------------------------+------------------+------------------------------------------------------------+-------------------------------------------------+ | | POST | _ignition/execute-solution | | Facade\Ignition\Http\Controllers\ExecuteSolutionController | Facade\Ignition\Http\Middleware\IgnitionEnabled | | | GET|HEAD | _ignition/health-check | | Facade\Ignition\Http\Controllers\HealthCheckController | Facade\Ignition\Http\Middleware\IgnitionEnabled | | | GET|HEAD | _ignition/scripts/{script} | | Facade\Ignition\Http\Controllers\ScriptController | Facade\Ignition\Http\Middleware\IgnitionEnabled | | | POST | _ignition/share-report | | Facade\Ignition\Http\Controllers\ShareReportController | Facade\Ignition\Http\Middleware\IgnitionEnabled | | | GET|HEAD | _ignition/styles/{style} | | Facade\Ignition\Http\Controllers\StyleController | Facade\Ignition\Http\Middleware\IgnitionEnabled | | | GET|HEAD | admin | admin.index | App\Http\Controllers\AdminController@index | web | | | POST | admin | admin.store | App\Http\Controllers\AdminController@store | web | | | GET|HEAD | admin/create | admin.create | App\Http\Controllers\AdminController@create | web | | | GET|HEAD | admin/{admin} | admin.show | App\Http\Controllers\AdminController@show | web | | | PUT|PATCH | admin/{admin} | admin.update | App\Http\Controllers\AdminController@update | web | | | DELETE | admin/{admin} | admin.destroy | App\Http\Controllers\AdminController@destroy | web | | | GET|HEAD | admin/{admin}/edit | admin.edit | App\Http\Controllers\AdminController@edit | web | | | GET|HEAD | admin/{id} | admin.deactivate | App\Http\Controllers\AdminController@deactivate | web | | | GET|HEAD | api/user | | Closure | api,auth:api | +--------+-----------+----------------------------+------------------+------------------------------------------------------------+-------------------------------------------------+

does anyone know whats wrong?

1

1 Answers

0
votes

Your route has some extra (id right after AdminController@deactivate which is not needed, please review and remove from your code, or edit your if it's just a typo in your question.