2017-08-22 38 views
-1

我有一個動作來停用用戶的資源。該操作使用一個位值來激活/停用資源,但我很驚訝我無法按預期設置位值。該值始終設置爲「1」,即資源創建時的默認值。如何在Laravel的雄辯中設置一個mysql位數據類型? (Laravel 5.4)

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(); 
    } 

即使我不認爲這個問題是我的模型,我使用的數據庫第一種方法,這是可能的,問題是我創建的模型。

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'; 
} 

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; 
+0

節目表架構上 –

回答

0

一些分鐘更新一次研究,我發現,MySQL有被存儲爲TINYINT(1)的布爾數據類型。

我已經改變了我的表

alter table resource modify column active boolean not null; 

現在我的控制器

$resource->active= false; //works