# Laravel Create Job 要在Laravel應用啟動時,就執行Schedule 需要先註冊他 ``` 'providers' => ServiceProvider::defaultProviders()->merge([ /* * Package Service Providers... */ /* * Application Service Providers... */ App\Providers\AppServiceProvider::class, App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, App\Providers\StartupServiceProvider::class,// add line ])->toArray(), ```   請建立一個class ``` php artisan make:job MyApiCallJob ``` StartupServiceProvider.php ``` <?php namespace App\Providers; use Illuminate\Support\Facades\Queue; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Artisan; use App\Jobs\MyApiCallJob; class StartupServiceProvider extends ServiceProvider { /** * Register services. */ public function register(): void { // } /** * Bootstrap services. */ public function boot(): void { Queue::push(new MyApiCallJob()); } } ``` ``` class MyApiCallJob implements ShouldQueue { public function __construct() { // } /** * Execute the job. */ public function handle(): void { //裡面放置要執行邏輯 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up