“Laravel Array Cast” Kode Jawaban

Konversi objek menjadi array Laravel

$person = new stdClass();
$person->firstName = "Taylor";
$person->age = 32;

//Convert Single-Dimention Object to array
$personArray = (array) $person;

//Convert Multi-Dimentional Object to Array
$personArray = objectToArray($person);
function objectToArray ($object) {
    if(!is_object($object) && !is_array($object)){
    	return $object;
    }
    return array_map('objectToArray', (array) $object);
}
Grepper

string ke array di Laravel

$explode_id = json_decode($request->data, true);
Obnoxious Okapi

Laravel Array Cast

use Illuminate\Database\Eloquent\Casts\AsCollection;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'options' => AsCollection::class,
];
Tiago F2

Laravel Array Cast

// just go to your desired model like User

class User extends Model{

  /**
 * The attributes that should be cast.
 *
 * @var array
 */
  
  protected $casts = [
      'names' => 'array',
  ]

}
Hamza Dev

Jawaban yang mirip dengan “Laravel Array Cast”

Pertanyaan yang mirip dengan “Laravel Array Cast”

Lebih banyak jawaban terkait untuk “Laravel Array Cast” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya