LaravelTreats icon indicating copy to clipboard operation
LaravelTreats copied to clipboard

declaration mismatch in laravel 8

Open silverax opened this issue 4 years ago • 5 comments

Declaration of LaravelTreats\Model\Traits\HasCompositePrimaryKey::setKeysForSaveQuery(Illuminate\Database\Eloquent\Builder $query) should be compatible with Illuminate\Database\Eloquent\Model::setKeysForSaveQuery($query)

silverax avatar Apr 14 '21 14:04 silverax

As a workarround I update the declaration inside vendor to: protected function setKeysForSaveQuery($query)

silverax avatar Apr 14 '21 14:04 silverax

Thanks for making this issue. I was looking into whether I could use this in my project.

sudofox avatar Apr 30 '21 12:04 sudofox

I ran into the same issue.

@silverax If you need to use the trait and still be able to use the trait in your code, you can use my code below. It 'inherits' the trait and overwrites the setKeysForSaveQuery() method. Make sure to put this trait in the right folder and replace any reference to the original trait with this one.

<?php

namespace App\Traits\Models;

use LaravelTreats\Model\Traits\HasCompositePrimaryKey as LaravelTreatsHasCompositePrimaryKey;

trait HasCompositePrimaryKey
{
    use LaravelTreatsHasCompositePrimaryKey
    {
        LaravelTreatsHasCompositePrimaryKey::setKeysForSaveQuery as parentSetKeysForSaveQuery;
    }

    protected function setKeysForSaveQuery($query)
    {
        return $this->parentSetKeysForSaveQuery($query);
    }
}

royvanv avatar May 19 '21 16:05 royvanv

I will try that in my next project!!!!!

Thanx!!

silverax avatar May 19 '21 20:05 silverax

Your decision helped me a lot.

I ran into the same issue.

@silverax If you need to use the trait and still be able to use the trait in your code, you can use my code below. It 'inherits' the trait and overwrites the setKeysForSaveQuery() method. Make sure to put this trait in the right folder and replace any reference to the original trait with this one.

<?php

namespace App\Traits\Models;

use LaravelTreats\Model\Traits\HasCompositePrimaryKey as LaravelTreatsHasCompositePrimaryKey;

trait HasCompositePrimaryKey
{
    use LaravelTreatsHasCompositePrimaryKey
    {
        LaravelTreatsHasCompositePrimaryKey::setKeysForSaveQuery as parentSetKeysForSaveQuery;
    }

    protected function setKeysForSaveQuery($query)
    {
        return $this->parentSetKeysForSaveQuery($query);
    }
}

ghost avatar Jun 10 '21 10:06 ghost