exodusanto / Laravel-Admin

Laravel-Admin is the new version of Laravel-Administrator of Frozennode
MIT License
39 stars 25 forks source link

BadMethodCallException getOwnerKey() and getForeignKey() in Fields/Relationships/BelongsTo.php and Columns/Relationships/BelongsTo.php #30

Closed jellesimons closed 4 years ago

jellesimons commented 5 years ago

Laravel version: 5.8.35 PHP version: 7.2.22 exodusanto/administrator version: 5.8.0

There is a problem with two method names inherited from Illuminate/Database/Eloquent/Relations/Relation.php

Method getOwnerKey() is named getOwnerKeyName() and method getForeignKey() is named getForeignKeyName().

In file Fields/Relationships/BelongsTo.php:

line 32: $options['foreign_key'] = $relationship->getForeignKeyName();

In File Columns/Relationships/BelongsTo.php:

-line 114: ' ON ' . $alias . '.' . $relationship->getOwnerKeyName() .

jmichaelterenin commented 4 years ago

I just upgraded to: PHP 7.2.24 Laravel version 5.8.35 exodusanto/administrator version: 5.8.0

and pages in Admin that were working for years are now broken (same error). Please respond when you have a chance. I'm not positive the solution is what the previous author outlined, but the error exists nonetheless.

exodusanto commented 4 years ago

Can someone share an example of model configuration?

jmichaelterenin commented 4 years ago

Hi exodusanto, Thank you for replying. It seems like you're not experiencing it at all? It's actually broken every page I've created. And this didn't occur when I upgraded to 5.8, it's when I upgraded to PHP 7.2.24.

I'll provide a model configuration shortly.

exodusanto commented 4 years ago

Thank you. I'm recently push on develop branch the update of methods name. Can you try the fix? In your composer.json add the VCS section and update the package version to dev-develop

jmichaelterenin commented 4 years ago

review.php:

`<?php

namespace App;

/*

require_once('uploadable.class.php');

class Review extends Uploadable {

/**
 * Ardent validation rules
 */
public static $rules = [
  'reservation_id' => 'required',
  'title' => 'required',
  'score' => 'required|integer|between:1,10',
];

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = 'reviews';

// MASS ASSIGNMENT -------------------------------------------------------
// define which attributes are mass assignable (for security)
// we only want these 2 attributes able to be filled

protected $fillable = ['reservation_id', 'title', 'blurb', 'score', 'reviewed'];

public static function boot()
{
    parent::boot();

    static::updating(function ($review) {
        // Set reviewed_on timestamp if it's being changed to 'reviewed'
        if ($review->reviewed && $review->isDirty(['reviewed'])) {
            $review->reviewed_on = date('Y-m-d H:i:s');
        }
    });
}

public function reservation()
{
    return $this->belongsTo('App\reservation');
}

} ` reviews.php:

`<?php /*

?> `

jmichaelterenin commented 4 years ago

Yes, that version is working as expected. Thank you for the fix. Let me know when it's committed.

exodusanto commented 4 years ago

Fixed in version 5.8.1