Skip to content

Instantly share code, notes, and snippets.

@tangorri
Last active January 4, 2016 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangorri/8580386 to your computer and use it in GitHub Desktop.
Save tangorri/8580386 to your computer and use it in GitHub Desktop.
got error : $ php artisan db:seed Seeded: UserTableSeeder Seeded: ProfessionTableSeeder Seeded: LanguageTableSeeder [BadMethodCallException] Call to undefined method Illuminate\Database\Query\Builder::associate() db:seed [--class[="..."]] [--database[="..."]]
<?php
class Customer extends Eloquent
{
public function user()
{
return $this->belongsTo('User');
}
public function profession()
{
return $this->hasOne('Profession');
}
public function emails()
{
return $this->hadMany('customer_emails');
}
}
<?php
class CustomerTableSeeder extends Seeder {
public function run()
{
$ant = new Customer;
$ant->name = 'Antoine';
$ant->surname = 'Malpel';
$ant->birthdate = date('1975-01-02');
$ant->title = 'Développeur';
$ant->gender = 'm';
$ant->profession = Profession::first();
$ant->nationality = 'fr';
$ant->retirement_date = date('2066-01-02');
$ant->comments = 'test customer (NOT REAL - DEV Purpose)';
$ant->phone_number = '01 01 01';
$ant->mobile_phone_number = '06 xx xx xx ';
//$ant->save();
$user = User::where('username', '=', 'antoine')->first();
$user->customer()->associate($ant);
$user->save();
/* $profession_id = Profession::first()->id;
$user_antoine = User::where('username', '=', 'antoine')->first();
$user_jerome = User::where('username', '=', 'jerome')->first();
DB::table('customers')->delete();
$customers = [
[
'user_id' => $user_antoine->id,
'name' => 'Antoine',
'surname' => 'Malpel',
'birthdate' => date('1975-01-02'),
'title' => 'Développeur',
'gender' => 'm',
'profession_id' => $profession_id,
'nationality' => 'fr',
'retirement_date' => date('2066-01-02'),
'comments' => 'test custimer (not real one)',
'phone_number' => '',
'mobile_phone_number' => '06 xx xx xx '
],
[
'user_id' => $user_jerome->id,
'name' => 'Jérôme',
'surname' => 'Nicolas',
'birthdate' => date('1971-05-06'),
'title' => 'Gérant',
'gender' => 'm',
'profession_id' => $profession_id,
'nationality' => 'fr',
'retirement_date' => date('2066-05-06'),
'comments' => 'test custimer (not real one)',
'phone_number' => '',
'mobile_phone_number' => '06 xx xx xx '
],
];
DB::table('customers')->insert($customers);*/
}
}
<?php
use Zizaco\Entrust\HasRole;
class User extends Eloquent
{
use HasRole; // add permissions relation
protected $hidden = array('password', 'confirmation_code');
public function customer()
{
return $this->hasOne('Customer');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment