forked from summerblue/larabbs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7f9c70
commit 22dc097
Showing
14 changed files
with
1,277 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
use App\Models\Topic; | ||
use App\Handlers\SlugTranslateHandler; | ||
|
||
class TranslateSlug implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
protected $topic; | ||
|
||
public function __construct(Topic $topic) | ||
{ | ||
// 队列任务构造器中接收了 Eloquent 模型,将会只序列化模型的 ID | ||
$this->topic = $topic; | ||
} | ||
|
||
public function handle() | ||
{ | ||
// 请求百度 API 接口进行翻译 | ||
$slug = app(SlugTranslateHandler::class)->translate($this->topic->title); | ||
|
||
// 为了避免模型监控器死循环调用,我们使用 DB 类直接对数据库进行操作 | ||
\DB::table('topics')->where('id', $this->topic->id)->update(['slug' => $slug]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use Laravel\Horizon\Horizon; | ||
use Illuminate\Support\Facades\Gate; | ||
use Laravel\Horizon\HorizonApplicationServiceProvider; | ||
|
||
class HorizonServiceProvider extends HorizonApplicationServiceProvider | ||
{ | ||
/** | ||
* Bootstrap any application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
parent::boot(); | ||
|
||
// Horizon::routeSmsNotificationsTo('15556667777'); | ||
// Horizon::routeMailNotificationsTo('[email protected]'); | ||
// Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel'); | ||
|
||
// Horizon::night(); | ||
} | ||
|
||
/** | ||
* Register the Horizon gate. | ||
* | ||
* This gate determines who can access Horizon in non-local environments. | ||
* | ||
* @return void | ||
*/ | ||
protected function gate() | ||
{ | ||
Gate::define('viewHorizon', function ($user) { | ||
return in_array($user->email, [ | ||
// | ||
]); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.