Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TestReturningElement.php (app/models)
- class TestReturningElement extends Eloquent {
- protected $table = 'test_returning_element';
- public $timestamps = false;
- // the primary key name
- public function getKeyName(){
- return "id3";
- }
- public static function insertAndGetElement()
- {
- $newElement = new TestReturningElement;
- $newElement->id1 = 5;
- $newElement->id2 = 5;
- $newElement->id3 = 6;
- $newElement->save();
- // those two lines give different results
- return $newElement;
- return TestReturningElement::find(6);
- }
- };
- //Database migration :
- public function up()
- {
- Schema::create('test_returning_element', function($table)
- {
- $table->integer('id1')->unsigned();
- $table->integer('id2')->unsigned();
- $table->integer('id3')->unsigned();
- $table->primary('id3');
- });
- }
- // TestController.php (app/controllers)
- class TestController extends BaseController
- {
- public function getTestCreation()
- {
- return TestReturningElement::insertAndGetElement();
- }
- }
- // routes.php
- Route::controller('test', 'TestController');
- // the result can be viewed on /test/test-creation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement