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;