Support the ongoing development of Laravel.io →
posted 9 years ago
Database
Last updated 2 years ago.
0

You didn't tell it what to insert:

DB::table('users')->insert(
    ['email' => '[email protected]', 'votes' => 0]
);

Need the key valure pairs.

0

jimgwhit said:

You didn't tell it what to insert:

DB::table('users')->insert(
   ['email' => '[email protected]', 'votes' => 0]
);

Need the key valure pairs.

So I was orignally trying to store an array of arrays. like here: http://stackoverflow.com/questions/20008687/store-arrays-of-da... but the result was the errors above.

I did fix this by removing the new table but it was tricky because originally I could only see one table in my db and not until I changed the name of my migration did the two tables show up in my db.

Steps:

-rename my migration table name (this the original one)

-enter the sqlite db from command line. (i can now see the conflicting table, I could not before)

-drop the regions table (the table causing the name conflict)

-change migration table name back. (in my editor, not from the command line)

-enter sqlite db again and rename the changed table name (this is the original one associated w/ my migration) back to the original name.

-run artisan:refresh

0

Did you get it working?

0

jimgwhit said:

Did you get it working?

yes and no. Yes in the sense that I no longer have errors on my tables, but I am still unsuccessful at storing any data to my tables.

By returning different things in my controller, I can see that I am parsing the array correctly, but when I put it into my model it's not going through

// Controller 

if($request->ajax()) {

        $data = $request->all();

        $inserts = array();
        foreach ( $data as $v ) {
            $inserts[] = array('start' => $v['start'], 'end' => $v['end']); 
        }
         // this will show my array being parsed correctly
        //return $inserts; 

        $regions = new Region($inserts);
        
         // this results in an empty array
        //return $regions;
        
       // there was nothing in $regions so nothing to save
        Auth::user()->regions()->save($regions);
// Model 
class Region extends Model {

	protected $table = 'regions';

	//protected $fillable = ['start', 'end', 'data'];
	protected $fillable = ['*'];

	public function user ()
	{
		return $this->belongsTo('App\User', 'user_id');
	}
}

I've been playing with my Model because that seems to be where my problem is but haven't made any progress.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

maxehnert maxehnert Joined 28 Apr 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.