0 votes

Hey everyone, i just wanted to say that one thing that has always been a pain is the time it takes to write out all the properties and model relationships into the code comments in order to get autocomplete in your IDE's.

I would imagine that this could be a very simple task for skipper to handle this because all of the relationships are already being defined for you.

Would it be too much to ask for the function return methods to show the proper relationships, and the abstract models to list out all the columns on the database along with their types?

/**
* @property int $id
* @property string $the_thing
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property \App\Models\Relation $relation
*/

That type of stuff would be super helpful and save us countless hours of typing :)

in Solved by (160 points)
recategorized by

Hello Ryan, I understand what you would like to achieve, but we would need some codebase for testing.

Unfortunately, one fragment isn't enough. We're not active Laravel developers so we would appreciate it if you can share you complete code together with documentation links where we can find all possible options.

Becasue of that I tried to contact you directly via email because to be able to work on this feature we would need slightly more cooperation from you.

So as I wrote before, would you be able to send us a complete example project which we can use for the development?

Thanks a lot
Ludek

Hey Ludek,

You can very easily understand this with a single abstract model file. You're already stubbing out the functions for the relationships or the "casts" for the model properties... all I'm saying is that you would want to add in another "model property" or "relation" in the class declaration.

<?php

 namespace App\Models\AbstractModels;

 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\SoftDeletes;

 /**
 * Class AbstractCustomer
 * @package App\Models
 *
 * @property int $id
 * @property int $team_id
 * @property string $email
 * @property string $first_name
 * @property string $last_name
 * @property string $cell_phone
 * @property string $profile_photo_path
 * @property \Carbon\Carbon $subscribed_to_email_at
 * @property \Carbon\Carbon $unsubscribed_to_email_at
 * @property \Carbon\Carbon $subscribed_to_mail_at
 * @property \Carbon\Carbon $unsubscribed_to_mail_at
 * @property \Carbon\Carbon $subscribed_to_sms_at
 * @property \Carbon\Carbon $unsubscribed_to_sms_at
 * @property \Carbon\Carbon $subscribed_to_phone_at
 * @property \Carbon\Carbon $unsubscribed_to_phone_at
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property \Carbon\Carbon $deleted_at
 * @property \App\Models\Team $team
 * @property \App\Models\Company|null $company
 * @property \Illuminate\Database\Eloquent\Collection $orders
 * @property \Illuminate\Database\Eloquent\Collection $orderDetails
 * @property \Illuminate\Database\Eloquent\Collection $addresses
 * @property \Illuminate\Database\Eloquent\Collection $notes
 * @property \Illuminate\Database\Eloquent\Collection $phoneNumbers
 * @property \Illuminate\Database\Eloquent\Collection $companies
 */
abstract class AbstractCustomer extends Model
{
    use SoftDeletes;

    /**
     * Primary key type.
     *
     * @var string
     */
    protected $keyType = 'string';

    /**
     * Primary key is non-autoincrementing.
     *
     * @var bool
     */
    public $incrementing = false;

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'string',
        'team_id' => 'string',
        'email' => 'string',
        'first_name' => 'string',
        'last_name' => 'string',
        'cell_phone' => 'string',
        'subscribed_to_email_at' => 'datetime',
        'subscribed_to_sms_at' => 'datetime',
        'subscribed_to_mail_at' => 'datetime',
        'subscribed_to_phone_at' => 'datetime',
        'unsubscribed_to_email_at' => 'datetime',
        'unsubscribed_to_sms_at' => 'datetime',
        'unsubscribed_to_mail_at' => 'datetime',
        'unsubscribed_to_phone_at' => 'datetime',
        'profile_photo_path' => 'string',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime'
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'team_id',
        'email',
        'first_name',
        'last_name',
        'cell_phone',
        'profile_photo_path'
    ];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

    public function team()
    {
        return $this->belongsTo('\App\Models\Team', 'team_id', 'id');
    }

    public function orders()
    {
        return $this->hasMany('\App\Models\Order', 'customer_id', 'id');
    }

    public function orderDetails()
    {
        return $this->hasMany('\App\Models\OrderDetail', 'customer_id', 'id');
    }

    public function addresses()
    {
        return $this->morphMany('\App\Models\Address', 'Addressable', 'addressable_type', 'addressable_id');
    }

    public function notes()
    {
        return $this->morphMany('\App\Models\Note', 'Noteable', 'noteable_type', 'noteable_id');
    }

    public function phoneNumbers()
    {
        return $this->morphMany('\App\Models\PhoneNumber', 'PhoneNumberable', 'phone_numberable_type', 'phone_numberable_id');
    }

    public function companies()
    {
        return $this->belongsToMany('\App\Models\Company', 'customer_has_company', 'customer_id', 'company_id')->withPivot('primary', 'title', 'division', 'phone', 'extension', 'notes', 'email');
    }
}

great, thanks!

It's clear now. We will try to implement it in next days and let you know with testing.

Hey thanks... I don't know if I mentioned this previously - but the main reason for this feature is that your models are all considered "untouchable" because they get overwritten. Typically I would want to add these mappings on the abstract file to keep smaller extended models / less to scroll through in the parent model but still get type-hinting.

I think I've defined "lazy" by asking for this, but the reality is it's a very reasonable benefit for a tool like this to provide. Why not right? :)

Thanks again for your help!

I don't think this is "lazy", it's time-saver and this is the reason why skipper is created ;-)

1 Answer

0 votes

New beta version with this feature is available here:

https://www.skipper18.com/support/402/downloads-skipper-beta

Please test it on your model and let me know.

by Skipper developer (141k points)