beaumind / eloquent-complement
add some usable features to laravel eloquent
1.0.1
2017-01-08 14:24 UTC
Requires
- php: >=5.4
- illuminate/support: ^5.0
This package is auto-updated.
Last update: 2024-11-19 16:42:49 UTC
README
add some usable features to laravel eloquent for laravel 5+.
Installation
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 { ... }
Save Associated models
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']);