“Laravel Array Cast” Code-Antworten

Konvertieren Sie das Objekt in 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

Saite zu Array in 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

Ähnliche Antworten wie “Laravel Array Cast”

Fragen ähnlich wie “Laravel Array Cast”

Weitere verwandte Antworten zu “Laravel Array Cast” auf PHP

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen