Advertisement
Guest User

Untitled

a guest
Mar 7th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. //TestReturningElement.php (app/models)
  2.  
  3. class TestReturningElement extends Eloquent {
  4.  
  5.     protected $table = 'test_returning_element';
  6.     public $timestamps = false;
  7.  
  8.     // the primary key name
  9.     public function getKeyName(){
  10.         return "id3";
  11.     }
  12.  
  13.     public static function insertAndGetElement()
  14.     {
  15.         $newElement = new TestReturningElement;
  16.         $newElement->id1 = 5;
  17.         $newElement->id2 = 5;
  18.         $newElement->id3 = 6;
  19.         $newElement->save();
  20.  
  21.         // those two lines give different results
  22.         return $newElement;
  23.         return TestReturningElement::find(6);
  24.     }
  25. };
  26.  
  27. //Database migration :
  28.  
  29. public function up()
  30. {
  31.     Schema::create('test_returning_element', function($table)
  32.     {
  33.         $table->integer('id1')->unsigned();
  34.         $table->integer('id2')->unsigned();
  35.         $table->integer('id3')->unsigned();
  36.  
  37.         $table->primary('id3');
  38.  
  39.     });
  40. }
  41.  
  42. // TestController.php (app/controllers)
  43.  
  44. class TestController extends BaseController
  45. {
  46.     public function getTestCreation()
  47.     {
  48.         return TestReturningElement::insertAndGetElement();
  49.     }
  50. }
  51.  
  52. // routes.php
  53.  
  54. Route::controller('test', 'TestController');
  55.  
  56. // the result can be viewed on /test/test-creation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement