Convert the model's attributes to an array.
public attributesToArray ( ) : array | ||
return | array |
class User extends Illuminate\Database\Eloquent\Model { protected $fillable = [ 'name', 'email', 'password' ]; }
$user = User::find(1); $array = $user->attributesToArray();
[ 'id' => 1, 'name' => 'John Doe', 'email' => 'john@example.com', 'password' => 'secret' ]
$user = User::find(1); $array = $user->attributesToArray(); unset($array['password']);The new array would not include the password field. In conclusion, the attributesToArray method in the Illuminate\Database\Eloquent\Model class is a useful tool for working with Eloquent models in Laravel PHP applications. The package library in question is Laravel's Eloquent ORM.