I get reference from here : https://github.com/jenssegers/laravel-mongodb
I make database and collection in mongodb. I don't make document and column in mongodb. Because it will automatically make the column and data type when insert the data
My controller, you can see this below :
public function create(array $attributes)
{
...
$result = User::create($attributes);
...
}
My model, you can see this below :
<?php
...
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Jenssegers\Mongodb\Eloquent\HybridRelations;
class User extends Eloquent
{
use HybridRelations;
use SoftDeletes;
protected $connection = 'mongodb';
public $table = 'users';
protected $dates = ['deleted_at'];
public $fillable = [
...
'name',
...
];
protected $casts = [
...
'name' => 'string',
...
];
}
When I insert data into mongodb, data type on mongodb will be automatically created based on input
How to set the data type in the model?
When I have an data type of data input : string
I can set it up to data type : integer
in my model
So, data type that is formed in mongodb is integer