jenssegers / model Goto Github PK
View Code? Open in Web Editor NEWThis model provides an eloquent-like base class that can be used to build custom models in Laravel and other frameworks
This model provides an eloquent-like base class that can be used to build custom models in Laravel and other frameworks
--please delete this issue!--
Please merge PR
#29
Thanks!
Thanks for the recent update! This is an exceptionally helpful and easy to use class. Would you consider adding the Laravel $dates auto-mutator?
Do you plan to add Eloquent's getDirty()
method (and its requirements)?
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?
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;
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! :)
Would be nice :D
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 :)
As you can check here https://packagist.org/packages/jenssegers/model last release taken by packagist was v1.1.2, could you please configure the autoupdate or at least press the button update once. Thank you
It'd be nice to have an attribute cast for Collections, since you already have illuminate/support
installed.
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,
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
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...
Could you give an example of more real-world usage, i.e how you would use a Model in a Controller?
Thanks
Please add support for Laravel 9. Thanks
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()
It seems like some of the tests on this package are not setup correctly. Would be great to get those fixed.
Hi!
Thanks for a great library! Is there any chance it will support Laravel 11 in the near future? ๐ค
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" => ....]
Any plans for Laravel 8 support?
It'd be nice to be able to control mass-assignable attributes just like in Eloquent.
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
This is really good. You should finish it. $fillable, $appends, $bla, $bla, $bla.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.