Package Data | |
---|---|
Maintainer Username: | beaumind |
Maintainer Contact: | a.hassani.sbu@gmail.com (A.Hassani) |
Package Create Date: | 2017-01-08 |
Package Last Update: | 2017-01-08 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-15 03:08:35 |
Package Statistics | |
---|---|
Total Downloads: | 15 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 0 |
Total Forks: | 0 |
Total Open Issues: | 0 |
add some usable features to laravel eloquent for laravel 5+.
Simply Run the Composer require comand.
composer require beaumind/eloquent-complement
use Beaumind\EloquentComplement\EloquentComplement;
class Question extends Model
{
use EloquentComplement;
public function user()
{
return $this->belongsTo('User');
}
public function answers()
{
return $this->hasMany('Answer');
}
}
class Answer extends Model
{
...
}
class User extends Model
{
...
}
you can now save question and related models in one step. it is atomic and it will role back on failure. also it fill foreign keys automatically.
$question['body'] = 'some question body';
$question['user']['name'] = 'joe';
$question['user']['username'] = 'joe_m';
...
$question['answers']['body'] = 'some answer body';
$question['answers']['is_correct'] = true;
now save in database.
(New Question())->saveAssociated($question, ['user','answers']);