getTranslations() return string and expecting array
See original GitHub issueHi there again @tabacitu
So as we spoke on #492 the problem really was MariaDB. I had to remove MariaDB and go with MySQL.
After that i run into some strange problem, so i will describe it to you.
This is my model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
use Backpack\CRUD\ModelTraits\SpatieTranslatable\Sluggable;
use Backpack\CRUD\ModelTraits\SpatieTranslatable\SluggableScopeHelpers;
use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
class Company extends Model
{
use CrudTrait;
use Sluggable, SluggableScopeHelpers;
use HasTranslations;
protected $translatable = ['name'];
When i create a new resource it get save into database.
The name becomes: {"en": "Bruno Tavares"}
And the slug: {"en": "{\"en\":\"bruno-tavares\"}"}
I think the slug is beeing generated from {"en": "Bruno Tavares"}
and not from "Bruno Tavares"
After saving to the database it returns to the list of companys, and that’s when i get the following error:
ErrorException in HasTranslations.php line 72:
Type error: Return value of App\Models\Company::getTranslations() must be of the type array, string returned (View: C:\wamp\www\megaboff\resources\views\vendor\backpack\crud\columns\text.blade.php) (View: C:\wamp\www\megaboff\resources\views\vendor\backpack\crud\columns\text.blade.php)
My fields on database are type JSON as i’v updated also doctrine/dbal to work with them within laravel.
Any idea why this could be happening?
EDIT PLEASE CONSIDER THE FOLLOWING:
When i use my seeder to populate the database with fake data i got the same formating in database as if i create a new model instance using the create crud. The error only happen if i have data created with seeder, if i delete the data created with seeder the error goes away.
What i did to test this ?
I created some companys using the seeder, and created another exactly the same but using the crud panel. (only id is diff) (btw, the sluggable shoudn’t ensure uniqueness?) After i deleted the ones generated by my seeders the error goes away, but i’m left with the same info in the database for the row i did not deleted as i had from the previous created with the seeder.
This is my factory:
$factory->define(App\Models\Company::class, function (Faker\Generator $faker) {
static $domain;
$tID = \App\Models\Template::inRandomOrder()->first()->id;
$name = $faker->name;
//$slug = str_slug($name);
return [
'name' => ['en' => $name],
'address' => $faker->address,
'email' => $faker->unique()->safeEmail,
'phone' => $faker->numerify('#########'),
'nif' => $faker->numerify('#########'),
'active' => $faker->boolean($chanceOfGettingTrue = 80),
'logo' => $faker->imageUrl($width = 640, $height = 480),
'default_lang' => $faker->languageCode,
'domain' => $domain ?: $domain = "www.backmotivos.dev",
'template_id' => $tID,
'extras' => json_encode($faker->creditCardDetails),
];
});
You can check this image: http://prntscr.com/ebnjr9
When i left only id 4 (the one i created using crud panel) it simply works …
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Is this issue still happening? I think this is a question rather than a bug but it could be a bug…
PS. I closed the issue as it’s been a while and nobody has reported on it. Feel free to reopen it if it’s still a bug.