Laravelのドキュメントを読んでいると、eloquentってワードが何度も出てきます。
なんとなく雰囲気でわかったような気でいましたが、eloquentって何でしょうか?
tinker・controllerでやっている以下のようなことでしょうか?
1 2 3 4 | $post = new Post(); $post ->title = $request ->title; $post ->body = $request ->body; $post ->save(); |
Model:model is a class that deal with database
モデルの作成
$ php artisan make:model Post
Model created successfully.
appフォルダにPost.phpが作られる
eloquentとは下のコードからもわかる様に、Modelのclass
databaseのtable nameがpostsなら、model nameはPost
1 2 3 4 5 6 7 | use Illuminate\Database\Eloquent\Model; class Post extends Model { // posts } |
1 2 3 4 5 6 7 8 9 | use App\Post; Route::get( '/read' , function (){ $posts = Post::all(); foreach ( $posts as $post ){ return $post ->title; } }); |