Paolo Resteghini
Paolo Resteghini

Reputation: 432

Update a single field in a row of a database

I'm trying to update the status from 'pending' to 'active'.

Here is my edit button:

<td>
    @if($c->status == 'active')
        <a href="{{ Route('admin.makeNotActive', ['id' => $c->id]) }}"><i class="fa fa-check fa-2x"></i></a>
    @else
        <a href="{{ Route('admin.makeActive', ['id' => $c->id]) }}"><i class="fa fa-times fa-2x"></i></a>
    @endif
</td>

My Routes:

get('admin/classified/activate/{id}', [
    'uses' => 'AdminController@makeNotActive',
    'as' => 'admin.makeNotActive',
]);

get('admin/classified/deactivate/{id}', [
    'uses' => 'AdminController@makeActive',
    'as' => 'admin.makeActive',
]);

and my methods:

public function makeActive($id)
{
    //dd('Trying to ACTIVATE');
    $c = Classified::findOrFail($id);
    $c->update(['status' => 'active']);
    return back();
}

public function makeNotActive($id)
{
    // dd('Trying to DEACTIVE');
    $c = Classified::findOrFail($id);
    $c->update(['status' => 'pending']);
    return back();
}

When I uncomment the dd's it's hitting them correctly but it's not updating. I'm pretty new to Laravel so may have done something obvious but I cannot see it!

Thanks in advance.

Upvotes: 1

Views: 204

Answers (1)

oseintow
oseintow

Reputation: 7371

public function makeActive($id)
{
   //dd('Trying to ACTIVATE');
   $c = Classified::findOrFail($id);
   $c->status ='active';
   $c->save();
   return back();
}

This should work for you.

Upvotes: 1

Related Questions