0

I have a single action to deactivate a user's resource. The action uses a bit value to activate/deactivate the resource but I was surprised that I couldn't set the bit value as I expected. The value is always set to "1", the default value when the resource is created.

   public function deactivate(Request $request)

        {

           $resourceId= $request->get('resourceId');

           $resource= \App\Resource::find($resourceId);

           //I've tried the two statements below separetely

           $resource->active= false; //didn't work

           $resource->active= 0;   //didn't work

            //I performed the test below with another column and it worked
            //so the problem isn't my model.

            $resource->anotherProperty = 10;



            $resource->save();
     }

even though I don't think the problem is my model, I'm using the database first approach and it is possible that the problem is the model I created.

class Resource extends Model
 {



 protected $table = 'resource';
  protected $primaryKey = 'resource_id';

protected $fillable = array( 'announcer_id', 'announcer_type', 'data',  'active');

   public $timestamps = false;
   protected $connection = 'custom_connection';
}

updated some minutes after

CREATE TABLE `resource` (
 `resource_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `announcer_id` int(10) unsigned NOT NULL,
 `announcer_type` tinyint(3) unsigned NOT NULL,
 `data` date DEFAULT NULL,
 `active` bit(1) DEFAULT b'1',
  PRIMARY KEY (`resource_id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=583 DEFAULT CHARSET=latin1;
1
  • show table schema Commented Aug 22, 2017 at 15:01

1 Answer 1

1

After research I found that MySQL has a boolean data type which is stored as tinyint(1).

I've altered my table

alter table resource modify column active boolean  not null;

now on my controller

$resource->active= false; //works
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.