Closed dragonattack closed 9 years ago
actually a simple
Category::create([]);
or
$c = new Category;
$c->save();
gives error too
[ErrorException]
Trying to get property of non-object
but it adds an empty entry to the DB though.
Did you try:
Category::create(['en' => ['title' => 'test 1', 'slug' => 'test-1', 'status' => 1]]);
this gives the same error:
[ErrorException]
Trying to get property of non-object
for Category it is possible to workaround like this:
$id = DB::table('categories')->insertGetId([]);
$c = Category::find($id);
$c->title = 'Title 1';
$c->slug = 'title-1';
$c->status = 1;
$c->save();
It's not very pretty, but it still works. But that won't work for Project
$id = DB::table('projects')->insertGetId([]);
$p = Project::find($id);
$p->title = 'Title 1';
$p->slug = 'title-1';
$p->status = 1;
$p->save();
Gives the above error
I did it this way and it works without any errors!
try {
$id = DB::table('projects')->insertGetId([]);
$p = Project::find($id);
$p->title = 'Title 1';
$p->slug = 'title-1';
$p->status = 1;
$p->save();
} catch (\Exception $e) {
dd($e);
}
I really not that good at it to understand why it only works that way and not the other.
And this not always works, and same code works from time to time. Well, it's weird.. Someone please help! :)
Perhaps a namespace problem ?
How to create any module entry (for example a Category) with Eloquent (I'm trying to use that from seeder)?
The problem with translation relations, so this could be just a Laravel question, but I'm new to this, so still can't figure it out.
but of course this gives a error
How to apply a translation field and do that right? Thank you.