Reputation: 147
I am very new to Laravel and PHP in general, most of what I have worked on has been relative to online tutorials. I know how to save single items like a username or password to my database but I am clueless when it comes to storing an entire file.This is how my database is currently formatted in my migration file:
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('username');
$table->string('email')->unique();
$table->string('password', 60);
$table->string('remember_token')->nullable();
$table->timestamps();
});
}
Any help is appreciated, let me know is more information about my project is needed.
Edit:
Example of JSON file similar to what I will be using:
{"Date 1": {
"Item 1": {
"para1": "word",
"para2": 100,
},
"Item 2": {
"para1": "word",
"para2": 100,
},
"Item 3": {
"para1": "word",
"para2": 100,
}
}
"Date 2": {
"Item 1": {
"para1": "word",
"para2": 100,
},
"Item 2": {
"para1": "word",
"para2": 100,
},
"Item 3": {
"para1": "word",
"para2": 100,
}
}}
Upvotes: 2
Views: 8990
Reputation: 6319
Add this line to your migration file:
$table->string('json');
Refresh your migrations
php artisan migrate:refresh
Add to your user object:
class User extends Eloquent
{
public $json;
}
Set the property as usual (a setter is recommended but not provided in this example)
$user = new User;
$user->json = json_encode( array('test-key' => 'test-data' ) );
Save
$user->save();
Upvotes: 7