Last active
August 29, 2015 14:25
-
-
Save rodurma/e6dc86b5fe5fd1d8a279 to your computer and use it in GitHub Desktop.
Recuperando o ID usando Eloquent do Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Post extends Eloquent | |
| { | |
| public $incrementing = false; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Post extends Eloquent | |
| { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use Illuminate\Http\Request; | |
| use App\Http\Controllers\Controller; | |
| use App\Post; | |
| class PostsController extends Controller | |
| { | |
| public function index(){ | |
| $post = new Post; | |
| $post->id = 123; // definimos o ID manualmente | |
| $post->title = "Primeiro Post"; | |
| $post->body = "Texto do primeiro post"; | |
| $post->save(); | |
| return $post->id; // isso agora ira imprimir 0 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use Illuminate\Http\Request; | |
| use App\Http\Controllers\Controller; | |
| use App\Post; | |
| class PostsController extends Controller | |
| { | |
| public function index(){ | |
| $post = new Post; | |
| $post->title = "Primeiro Post"; | |
| $post->body = "Texto do primeiro post"; | |
| $post->save(); | |
| return $post->id; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment