andrechalom

Experience

240

0 Best Reply Awards

  • Member Since 3 Months Ago
  • 1 Lesson Completed
  • 0 Favorites

14th September, 2017

andrechalom left a reply on Having Trouble To Set Up Auto-discovery For A Facade • 1 week ago

Hello, clay. Thanks for your input! You can load the "dev-master" from packagist, which has the required composer directives.

andrechalom started a new conversation Having Trouble To Set Up Auto-discovery For A Facade • 1 week ago

Hi! I'm developing a small package for Laravel, and it's working fine under Laravel 5.4. I'm trying to provide the composer rules for the new auto-discovery on Laravel 5.5, but it is failing to find the required class. I wasn't able to find any in-depth documentation of the auto-discovery, but from the changes in Laravel Debugbar and from the Laracast's Video it seems that the syntax is pretty straightforward:

   "extra": {
        "branch-alias": {
            "dev-master": "1.0-dev"
        },
        "laravel": {
            "providers": [
                "AndreChalom\\LaravelMultiselect\\MultiselectServiceProvider"
            ],
            "aliases": {
                "Multiselect": "AndreChalom\\LaravelMultiselect\\MultiselectFacade"
            }
        }
    },  

The MultiselectFacade and MultiselectServiceProvider are working fine when explicitly included in the config/app.php file, and I can use the {!! Multiselect::select(...) !!} just fine in my blade templates. I can also comment out the "MultiselectServiceProvider" line and everything works fine - the provider is auto-discovered and registers the Multiselect service. Yay!

However, if I delete the "MultiselectFacade" line from the config/app.php, relying on the auto-discovery, suddenly the application fails with "Class 'Multiselect' not found". What I may be missing? How can I debug this?

13th June, 2017

andrechalom left a reply on Trouble With MorphOne / MorphTo With Non-default Id Columns • 3 months ago

Thanks. I'll rewrite the models.

9th June, 2017

andrechalom left a reply on Trouble With MorphOne / MorphTo With Non-default Id Columns • 3 months ago

Thanks for the input. However, I don't think this is related to the problem I'm reporting. The problem I'm having is: why does the MorphTo method in the Object class return null?

MariaDB [opendatabio]> select * from objects;
+-----------+--------------+------+------------------+---------------------+---------------------+
| object_id | object_type  | note | bib_reference_id | created_at          | updated_at          |
+-----------+--------------+------+------------------+---------------------+---------------------+
|         1 | App\Location | NULL |                1 | 2017-06-09 00:38:44 | 2017-06-09 01:15:14 |

Shouldn't App\Object::find(1)->content return an instance of App\Location?

andrechalom left a reply on Trouble With MorphOne / MorphTo With Non-default Id Columns • 3 months ago

Thanks for your answer. I had ommited the other models, as they are not relevant to the question, but the Object may link to Locations, Buildings, Persons, etc. All of those models have a similar structure.

class Building extends Model
{
        protected $primaryKey = 'object_id';
        public function object() {
                return $this->morphOne('App\Object', 'object');
        }
}

And so on.

8th June, 2017

andrechalom started a new conversation Trouble With MorphOne / MorphTo With Non-default Id Columns • 3 months ago

I'm having some trouble using polymorphic relations on Laravel 5.4. My idea is having a "base" Object class, with "derived" objects such as Location and Sample. So, I've made this migrations (removed some non-related attributes)

        Schema::create('objects', function (Blueprint $table) {
            $table->increments('object_id'); // used by Laravel's morphTo
            $table->string('object_type'); // used by Laravel's morphTo
            $table->timestamps();
        });
       Schema::create('locations', function (Blueprint $table) {
            $table->integer('object_id')->unsigned();
            $table->foreign('object_id')->references('object_id')->on('objects');
            $table->primary('object_id');
            $table->timestamps();
       });

And I'm using the following models

class Location extends Model
{
        protected $primaryKey = 'object_id';
        public function object() {
                return $this->morphOne('App\Object', 'object');
        }
}
class Object extends Model
{
        protected $primaryKey = 'object_id';
        public function content() {
                return $this->morphTo();
        }
}

Now, I can create Objects with their respective Location with no problem.

>>> $l = new App\Location;
>>> $ob = new App\Object;
>>> $l->object()->save($ob);
>>> $l->object_id = $ob->id;
>>> $l->save();

I can confirm that both Object and Location are stored in the database. However, trying to get an Object's content fails

>>> $a = App\Location::find(1);
=> App\Location {#798
     object_id: 1,
     name: "Brazil",
     parent_id: null,
     created_at: "2017-06-09 00:38:52",
     updated_at: "2017-06-09 00:38:52",
   }
>>> $a->object;
=> App\Object {#778
     object_id: 1,
     object_type: "App\Location",
     note: null,
     bib_reference_id: 1,
     created_at: "2017-06-09 00:38:44",
     updated_at: "2017-06-09 01:15:14",
   }
>>> $b = App\Object::find(1);
=> App\Object {#791
     object_id: 1,
     object_type: "App\Location",
     note: null,
     bib_reference_id: 1,
     created_at: "2017-06-09 00:38:44",
     updated_at: "2017-06-09 01:15:14",
   }
>>> $b->content()
=> Illuminate\Database\Eloquent\Relations\MorphTo {#778}
>>> $b->content
=> null

Does anyone know what can I do here? Is this related to the "id column" being non-standard? Is there a way to pass the "id column" to the MorphTo?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.