title: How to save a JSON response in Database with Laravel Eloquent, I'm getting an error "Array to string conversion"
body: <h2>** Error: "Array to string conversion" **</h2>
  
  <p>I'm trying to save a JSON(string) with Eloquent into the database but 
   I'm getting an error: <b>"Array to string conversion"</b></p>
  
  <p>I try to add in my model:</p>
  
  <p><code>protected $casts = ['payload' =&gt; 'array'];</code></p>
  
  <p>or </p>
  
  <p><code>protected $casts = ['payload' =&gt; 'json'];</code></p>
  
  <p>but is not working!</p>
  
  <p><b>Controller</b></p>
  
  <pre>
  
      try{
          if( $type == 'b2c'){
              $searchEnquiry = B2CSearchEnquiry::find($enquiryID);
              $data = $this->searchInDataSource($searchEnquiry);
  
              $repuveConsult = new B2cRepuveConsult;
              $repuveConsult->search_enquiry_id = $enquiryID;
              $repuveConsult->payload = (string)$data;
              $repuveConsult->saveOrFail();
          }
      }catch(\Exception $e){
          return $e->getMessage();
      }
  
  </pre>
  
  <p><b>Model</b></p>
  
  <pre>
  
      class B2cRepuveConsult extends Model
      {
          protected $table = ['b2c_repuve_consults'];
          protected $fillable = ['search_enquiry_id','information'];
          protected $casts = [
              'information' => 'array',
          ];
      }
  
  </pre>
  
  <p><b>Migration</b></p>
  
  <pre>
  
  
      public function up()
          {
              Schema::create('b2c_repuve_consults', function (Blueprint $table) {
                  $table->increments('id');
                  $table->integer('search_enquiry_id')->unsigned();
                  $table->longText('payload')->nullable();
                  $table->timestamps();
              });
  
              Schema::table('b2c_repuve_consults', function($table) {
                  $table->foreign('search_enquiry_id')
                      ->references('id')
                      ->on('b2c_search_enquiries')
                      ->onDelete('cascade');
              });
          }
  
  </pre>
  
  <p>A raw query works but is not a good practice since I'm using Laravel</p>
  
  <pre>
        DB::insert('insert into b2c_repuve_consults (search_enquiry_id,payload) values (?, ?)', [$enquiryID, $data]);
  
  </pre>