//路由定義 Route::get('/', function () { return view('welcome'); }); //控制器定義 class PostController extends Controller { public function index() { $posts = Post::all(); return view('posts.index', compact('posts')); } }
//Eloquent查詢數據 $users = DB::table('users')->where('name', 'John')->get(); //創建遷移文件 php artisan make:migration create_users_table //運行遷移 php artisan migrate //填充種子數據 php artisan make:seeder UsersTableSeeder //運行Seeder php artisan db:seed
//定義一個任務 class SendEmail implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $user; public function __construct(User $user) { $this->user = $user; } public function handle() { Mail::to($this->user->email)->send(new WelcomeEmail($this->user)); } } //將任務添加到隊列 dispatch(new SendEmail($user));
上一篇java站編號和站名
下一篇python畫圖隱藏圖像