Coder Social home page Coder Social logo

model's People

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  avatar  avatar  avatar

model's Issues

$dates

Thanks for the recent update! This is an exceptionally helpful and easy to use class. Would you consider adding the Laravel $dates auto-mutator?

getDirty()

Do you plan to add Eloquent's getDirty() method (and its requirements)?

Problem with using this

Hello.

So I installed this package with composer.

I then created a new Laravel model:

<?php
    
    namespace App;

    use Jenssegers\Model;

    class Test extends Model {
    
    }

Which resulted in PHP Fatal error: Class 'Jenssegers\Model' not found

I then changed the use statement to

use \Jenssegers\Model;

Which resulted in the same error.

What am I doing wrong? How can I correctly extend this class to write a custom Model?

snake case attributes

Hi, great work!

It is possible that i define attributes like this:
protected $attributes = [
"id" => null,
"id_conflict" => false,
"sync_info_loaded" => false
];

And set and get these attributes like this:
$project->idConflict = true;
$project->syncInfoLoaded= true;

Laravel 6.0 Compatibility

Adding this as a placeholder to track compatibility until it gets update. I will try to submit a PR, if I can find time. Thanks! :)

Collection merge does not work without an overridden getKey() method

I realised that if you want to merge two collections like this:

$collection1->merge($collection2)

You will get an exception saying that you haven't implemented a getKey() method. After som digging around, I found that, as long as you implement this method on the model and return something unique for each model instance, the merge will work.

I guess my tip is that the getKey() method is implemented in the Model.php file and that the developers using this package can provide an id attribute which is unique for all model instances :)

How to take advantage of eloquent relationships?

Hi,

This looks great for my new project.

Can you please give more documentation on how to use eloquent relationships?

More details: I'm building a Client Portal for SuiteCRM. I'm using the REST api to fetch the data. In the crm contacts have one to many relationships with the cases model. I would like to reflect this relationship in the Laravel, so I can do something like this:

$cases = Contact::find(id)->cases;

Can you please you give example of how to use relationships with your model?

Thanks,

$date-mutators support

setAttribute to support $dates

        // If an attribute is listed as a "date", we'll convert it from a DateTime
        // instance into a form proper for storage on the database tables using
        // the connection grammar's date format. We will auto set the values.
        elseif ($value && $this->isDateAttribute($key)) {
            $value = $this->fromDateTime($value);
        }

https://laravel.com/docs/7.x/eloquent-mutators#date-mutators

can i use it with codeigniter ?

hello bro..
can i use this library with codeigniter framework, and if it can be, how to use it in codeigniter fw ?

the other question :
is this library inherit all the features of eloquent laravel 4.1 such as polymorphm relations, eager/lazy loading and else ?

thanks for your answer... bro...

More documentation?

Could you give an example of more real-world usage, i.e how you would use a Model in a Controller?

Thanks

Using jensseger hybridrealations trait causes error

When I use HybridRelations in my sql model

use GeneratesUuid, HasFactory, SoftDeletes, HybridRelations;
I get this error when calling hasOneThrough relation Call to undefined method Illuminate\Database\Eloquent\Relations\HasOneThrough::getOwnerKeyName()

Laravel 11 support?

Hi!

Thanks for a great library! Is there any chance it will support Laravel 11 in the near future? ๐Ÿคž

Add append function

Hi

Love the library.

How do you feel about adding the append method that is currently missing.

/**
 * Append attributes to query when building a query.
 *
 * @param  array|string  $attributes
 * @return $this
 */
public function append($attributes)
{
    $this->appends = array_unique(
        array_merge($this->appends, is_string($attributes) ? func_get_args() : $attributes)
    );

    return $this;
}

This way we can append dynamically and they'll be present when the final model is requested via toArray();

$model->append('thing');

$model->toArray(); // includes ["thing" => ....]

Return Type Warnings

I'm receiving the following warning when running in PHP 8.1 and Laravel 9 (I have not tested other PHP or Laravel versions):

[2022-06-11 16:10:17] local.WARNING: Return type of Jenssegers\Model\Model::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/jenssegers/model/src/Model.php on line 900  
[2022-06-11 16:10:17] local.WARNING: Return type of Jenssegers\Model\Model::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/jenssegers/model/src/Model.php on line 444  

from good to great

This is really good. You should finish it. $fillable, $appends, $bla, $bla, $bla.

Static API class implementation

Your example is that of a static API class: API::post('/items', $this->attributes);.

Currently, my custom API client is injected into my controller and not static. This allows me to authenticate in the constructor and call the API from the controller's instance.

I would like to use this package to define a model for the controller to use instead. However, being new to Laravel and assuming I cannot inject my API Client into my model, I tried to convert it to a static class. However, it seems to me this would mean I would need to run the authentication for every call. Though, thinking about this out loud, perhaps I can store the token in session.

Any thoughts on this? Am I missing something obvious?

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.