classUserextendsAuthenticatable{use HasFactory, Notifiable;/** * The attributes that are mass assignable. * * @vararray*/protected$fillable =['name','email','password',];/** * The attributes that should be hidden for arrays. * * @vararray*/protected$hidden =['password','remember_token',];/** * The attributes that should be cast to native types. * * @vararray*/protected$casts =['email_verified_at'=>'datetime',];}
$ php artisan make:model Post
$ php artisan make:model Author
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use HasFactory;
}
>>> DB::select('SELECT * FROM posts');
>>> DB::insert('INSERT INTO posts(title,body) VALUES(?.?), ['Hello','Hi']);
>>> $posts = DB::select('SELECT * FROM posts');
>>> $posts[0]->title;
>>> $posts = DB::selectOne('SELECT * FROM WHERE id = ?',[1]);