// app/Post.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model {}
try
Route::get('posts/new', function(){
// Create a new instance of the Post model
$post = new App\Post;
// Assign values to model’s attributes
$post->title = "My first post";
// Assign values to model’s attributes
$post->body = "This post is created with Eloquent";
// Insert the record in the DB
$post->save();
// Display the new record containing the blog post
return $post;
});
// Retrieve a record with primary key (id) equal to “2”
$comment = Comment::find(2);
// If there is a comment with ID “2”, The $comment variable will contain:
/*
object(Comment)#137 (20) {
["attributes":protected]=> array(5) {
["id"]=>
string(1) "2"
["post_id"]=>
string(1) "1"
["body"]=>
string(17) "My second comment"
...
}
...
}
*/