Closed curtisdelicata closed 4 years ago
You probably forgot you extend the person-form from the package.
Can you explain what I did wrong? PersonForm doesn't extend it has just been binded as per docs? Does it need to extend too?
Changed to class PersonForm extends \LaravelEnso\People\Forms\Builders\PersonForm and still has error.
Oh, now it says about being compatible.
production.ERROR: Declaration of App\Forms\Builders\PersonForm::edit(App\Person $person) should be compatible with LaravelEnso\People\Forms\Builders\PersonForm::edit(LaravelEnso\People\Models\Person $person) {"userId":2,"exception":"[object] (ErrorException(code: 0): Declaration of App\Forms\Builders\PersonForm::edit(App\Person $person) should be compatible with LaravelEnso\People\Forms\Builders\PersonForm::edit(LaravelEnso\People\Models\Person $person) at /home/genealogia/public_html/app/Forms/Builders/PersonForm.php:29)
My App\Person doesn't extend the Person model as it errored about cascade morph map so I had to copy all the functions instead and extend Model. Is this why?
I'm now extending default Person model after removing duplicate MorphCascade trait and same error on form about compatible $person
This is my Person:
`<?php
namespace App;
use LaravelEnso\Companies\Models\Company; use App\Models\User; use App\Family; use App\Place; use App\PersonEvent; use LaravelEnso\DynamicMethods\Traits\Relations; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Notifications\RoutesNotifications; use Illuminate\Support\Collection; use LaravelEnso\Addresses\Traits\Addressable; use LaravelEnso\Helpers\Traits\AvoidsDeletionConflicts; use LaravelEnso\Multitenancy\Traits\SystemConnection; use LaravelEnso\People\Enums\Genders; use LaravelEnso\People\Enums\Titles; use LaravelEnso\Rememberable\Traits\Rememberable; use LaravelEnso\Tables\Traits\TableCache; use LaravelEnso\TrackWho\Traits\CreatedBy; use LaravelEnso\TrackWho\Traits\UpdatedBy;
class Person extends \LaravelEnso\People\Models\Person { use Addressable, AvoidsDeletionConflicts, CreatedBy, Relations, Rememberable, RoutesNotifications, TableCache, UpdatedBy, SoftDeletes, SystemConnection;
public function __construct(Array $attributes = [])
{
parent::__construct($attributes);
}
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at', 'birthday','deathday'];
protected $guarded = ['id'];
protected $fillable = [
'gid',
'givn',
'surn',
'sex',
'child_in_family_id',
'description',
'title', 'name', 'appellative', 'uid', 'email', 'phone', 'birthday',
'deathday', 'bank', 'bank_account',
'uid', 'chan', 'rin', 'resn', 'rfn', 'afn',
];
public function events()
{
return $this->hasMany(PersonEvent::class);
}
public function child_in_family()
{
return $this->belongsTo(Family::class, 'child_in_family_id');
}
public function husband_in_family()
{
return $this->hasMany(Family::class, 'husband_id');
}
public function wife_in_family()
{
return $this->hasMany(Family::class, 'wife_id');
}
public function fullname()
{
return $this->givn.' '.$this->surn;
}
public function getSex()
{
if ($this->sex == 'F') {
return 'Female';
}
return 'Male';
}
public static function getList()
{
$persons = self::get();
$result = [];
foreach ($persons as $person) {
$result[$person->id] = $person->fullname();
}
return collect($result);
}
public function addEvent($title, $date, $place, $description = '')
{
$place_id = Place::getIdByTitle($place);
$event = PersonEvent::updateOrCreate(
[
'person_id' => $this->id,
'title' => $title,
],
[
'person_id' => $this->id,
'title' => $title,
'description' => $description,
]);
if ($date) {
$event->date = $date;
$event->save();
}
if ($place) {
$event->places_id = $place_id;
$event->save();
}
// add birthyear to person table ( for form builder )
if ($title == 'BIRT' && ! empty($date)) {
$this->birthday = date('Y-m-d', strtotime($date));
}
// add deathyear to person table ( for form builder )
if ($title == 'DEAT' && ! empty($date)) {
$this->deathday = date('Y-m-d', strtotime($date));
}
$this->save();
return $event;
}
public function birth()
{
return $this->events->where('title', '=', 'BIRT')->first();
}
public function death()
{
return $this->events->where('title', '=', 'DEAT')->first();
}
public function appellative()
{
return $this->givn;
}
protected $touches = ['user'];
public function user()
{
return $this->hasOne(\LaravelEnso\Core\Models\User::class);
}
public function companies()
{
return $this->belongsToMany(Company::class)
->withPivot(['position', 'is_main']);
}
public function hasUser()
{
return $this->user()->exists();
}
public function company()
{
return $this->companies()->wherePivot('is_main', true)->first();
}
public function gender()
{
if (! $this->title) {
return;
}
return $this->title === Titles::Mr
? Genders::Male
: Genders::Female;
}
public function position(Company $company)
{
return $this->companies()
->wherePivot('company_id', $company->id)
->first()->pivot->position;
}
public function syncCompanies($companyIds, $mainCompanyId)
{
$pivotIds = (new Collection($companyIds))
->reduce(fn ($pivot, $value) => $pivot->put($value, [
'is_main' => $value === $mainCompanyId,
'is_mandatary' => false,
]), new Collection());
$this->companies()->sync($pivotIds->toArray());
}
} `
@curtisdelicata has been this solved?
production.ERROR: Argument 1 passed to LaravelEnso\People\Http\Controllers\Create::invoke() must be an instance of LaravelEnso\People\Forms\Builders\PersonForm, instance of App\Forms\Builders\PersonForm given {"userId":2,"exception":"[object] (TypeError(code: 0): Argument 1 passed to LaravelEnso\People\Http\Controllers\Create::invoke() must be an instance of LaravelEnso\People\Forms\Builders\PersonForm, instance of App\Forms\Builders\PersonForm given at /home/genealogia/public_html/vendor/laravel-enso/people/src/Http/Controllers/Create.php:10)
I am binding and it worked before. The only difference is I'm trying to manually add multi tenancy code to the table builder and forms as overwriting the route didn't work for me, unless I did that wrong?