Closed leite closed 8 years ago
This would be because the library uses Laravel facades to dispatch the model events. Without using the Laravel container (I believe) the calls on the facades aren't forwarded to the right objects.
We could take a look at trying to replace the Facades in the package, but I'm not sure how we would be able to do that in a simple way. Unfortunately I don't have a good solution for using this package outside of Laravel. Happy to accept a PR that fixes this but it's not an issue for most of the users. Sorry!
Actually, there was some discussion about dropping facades in #132, so might be worthwhile keeping an eye on that thread.
Also sorry for taking so long to respond, I must have missed the notification for this issue.
wonder what @leite did to overcome this hurdle....I too am using Slim PHP
Just adding this here. I found this package https://github.com/itsgoingd/slim-services ....but not sure how to incorporate the validation into it to make it work...any idea how your package can be integrated here using this?
nice @karneaud, I did nothing hehehe ... my app have validation on the front side and some double checks for uniqueness in the backend.
As you can see I am extending core\Model ... I guess you could create something like this and take advantage of slim-services
namespace core;
class Model extends Illuminate\Database\Eloquent\Model {
private $_errors;
function errors () {
return $this->_errors;
}
static function boot () {
parent::boot();
static::saving(function ($model) {
$validator = \Slim\Slim::getInstance()
->validator->make($model->attributes, $model->rules);
if ($validator->fails()) {
$model->_errors = $validator->errors();
return false;
}
return true;
});
}
}
I would love to see the someone take some action about this (I'm kind busy at time), as to the author, please leave that issue open.
I've been trying to see how I can adapt it but must admit my knowledge with facade pattern is young. Was not able to get it to work
Hi,
Nice lib, I'm having a trouble setting up validation in an eloquent model, my enviroment as follows:
core/Model.php
the so called model in models/Users.php
this is how I set up eloquent in core/Bootstrap.php
this is the composer.json
the problem is - everytime a call the seeder a get this error:
db/seeds/2015_04_27_21192206_users_seed.php
for the record: