Giter Site home page Giter Site logo

laraveltreats's People

Contributors

brad-jones avatar mopo922 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

laraveltreats's Issues

Model Events not firing

I recently found this, and it perfectly handles what I wanted to do. However one problem with it is that it doesn't fire (at least) the eloquent.deleted event.

If you look at this issue - laravel/framework#2536 I was originally thinking that it was this that was the problem. However if you do it as the issue explains;

Analytic::where('id', 2)->first()->delete();

or

$analytics = Analytic::where('id', '>', 100)->get();

foreach ($analytics as $analytic) {
    $analytic->delete();
}

or

Analytic::where('id', '>', 100)->get()->each(function($analytic) {
    $analytic->delete();
});

Basically loading the data into memory by calling first() or using the each function on the collection.

Unfortunately the only way I have found so far to get the event to fire was to manually check the boolean response of delete() and then fire the event myself;

$analytic = Analytic::where('id', 100)->first();
$deleted = $analytic->delete();

if ($deleted) {
    event("eloquent.deleted: " . Analytic::class, [
        $analytic,
    ]);
}

return [
    "success" => $deleted,
];

I don't know if the other events fire at the moment, but at least the deleting and deleted events aren't firing.

Error with chunk()

I found a bug when using chunk on an Eloquent model instead of get.

Laravel calls a function enforceOrderBy that orders the query based on the primary key.

/**
  * Add a generic "order by" clause if the query doesn't already have one.
  *
  * @return void
  */
 protected function enforceOrderBy()
 {
     if (empty($this->query->orders) && empty($this->query->unionOrders)) {
         $this->orderBy($this->model->getQualifiedKeyName(), 'asc');
     }
 }

/**
  * Get the table qualified key name.
  *
  * @return string
  */
 public function getQualifiedKeyName()
 {
     return $this->qualifyColumn($this->getKeyName());
 }

 /**
  * Qualify the given column name by the model's table.
  *
  * @param  string  $column
  * @return string
  */
 public function qualifyColumn($column)
 {
     if (Str::contains($column, '.')) {
         return $column;
     }
 
     return $this->getTable().'.'.$column;
 }

You can circumvent this by adding your own orderBy but perhaps you could override the getQualifiedKeyName, qualifyColumn or the getKeyName function to prevent this from being necessary?

php compatibility

Why is php version 7 required? I work with servers contracted with php 5.6, and for that reason alone I can not install this very practical library through composer.json, and instead, I have included the files manually, and it works well even with that older version of php It is not a serious matter, but if it is necessary to maintain the neat structure of the project, put the oldest version that is supported, unless there is a precise reason why it has been put version 7 as required.

PHP 5.6 compatibility

Hi there. First off, the HasCompositePrimaryKeytrait has saved me from a major headache, many thanks for creating this!

Second, is there a reason why this has the php requirement set to 7.0? I don't think I see anything that cannot run in 5.6 but I've only looked in that particular trait.

I'm currently migrating a project from 5.6 and evaluating this library but would still need to run this under 5.6 for some time before updating to 7.0.

declaration mismatch in laravel 8

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

delete HasCompositePrimaryKey

Hi,
I see the methods setKeysForSaveQuery() and find() in the trait, but I was wondering how the delete() would work ? No risk of deleting everything

Composite Keys don't work on Pivot Tables

When attempting to execute a hasManyThrough relationship via a table with a composite key, Laravel attempts to assume the JOIN-ON field to be the primary key assigned to the pivot model. If the key is an array using your HasCompositePrimaryKey trait, you end up with an "Array to string conversion" error. This appears to be happening in Model::getQualifiedKeyName() when it calls getKeyName(). That means, just for a start, you'd have to be mindful of all 10 places getQualifiedKeyName gets called, and all 29 places getKeyName gets called, all currently expecting a string response.

Collection method first throws an exception when using HasCompositePrimaryKey

Collection method first throws an exception when using HasCompositePrimaryKey:

$sources = $sources->first(function($model) { return $model->getKey() === 1; });

[ErrorException]
array_key_exists(): The first argument should be either a string or an integer

Exception trace:
() at /git/api/src/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:311
Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at n/a:n/a
array_key_exists() at /git/api/src/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:311
Illuminate\Database\Eloquent\Model->getAttribute() at /git/api/src/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1265
Illuminate\Database\Eloquent\Model->getKey() at /git/api/src/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php:34
Illuminate\Database\Eloquent\Collection->Illuminate\Database\Eloquent{closure}() at n/a:n/a
call_user_func() at /git/api/src/vendor/laravel/framework/src/Illuminate/Support/Arr.php:175
Illuminate\Support\Arr::first() at /git/api/src/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php:35

not working with hasOne?

I am not sure how to make it work with hasOne

Code is

Program::with('type')->find(['id' => 1, 'year' => 2018]);

in the model

public function type()
    {
        return $this->hasOne('Type', 'id', 'type_id');
    }

I get

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: Eloquent/Model.php

Line Number: 1149
An uncaught Exception was encountered

Type: Illuminate\Database\QueryException

Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'programs.Array' in 'where clause' (SQL: select * from `programs` where `programs`.`Array` in (1, 2018))

Filename: /shared/httpd/humber/hq/application/vendor/illuminate/database/Connection.php

Line Number: 647

Thanks

PS: I saw there might be a new version coming soon, how soon?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.