在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):spatie/laravel-welcome-notification开源软件地址(OpenSource Url):https://github.com/spatie/laravel-welcome-notification开源编程语言(OpenSource Language):PHP 93.8%开源软件介绍(OpenSource Introduction):Send a welcome notification to new usersUsing this package you can send a $expiresAt = now()->addDay();
$user->sendWelcomeNotification($expiresAt); Support usWe invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products. We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall. InstallationYou can install the package via composer: composer require spatie/laravel-welcome-notification Migrating the databaseYou must publish the migrations provided by this package by executing this command: php artisan vendor:publish --provider="Spatie\WelcomeNotification\WelcomeNotificationServiceProvider" --tag="migrations" Next, you must migrate your database. php artisan migrate Preparing the user modelYou must apply the Preparing the WelcomeControllerNext you'll need to create a controller of your own that will extend namespace App\Http\Controllers\Auth;
use Spatie\WelcomeNotification\WelcomeController as BaseWelcomeController;
class MyWelcomeController extends BaseWelcomeController
{
} Registering the routesYou'll have to register these routes: use Spatie\WelcomeNotification\WelcomesNewUsers;
use App\Http\Controllers\Auth\MyWelcomeController;
Route::group(['middleware' => ['web', WelcomesNewUsers::class,]], function () {
Route::get('welcome/{user}', [MyWelcomeController::class, 'showWelcomeForm'])->name('welcome');
Route::post('welcome/{user}', [MyWelcomeController::class, 'savePassword']);
}); Preparing the welcome form viewThe php artisan vendor:publish --provider="Spatie\WelcomeNotification\WelcomeNotificationServiceProvider" --tag="views" UsageHere's how you can send a welcome notification to a user that you just created. $expiresAt = now()->addDay();
$user->sendWelcomeNotification($expiresAt); Handling successful requestsAfter the a user has successfully set a new password the use Symfony\Component\HttpFoundation\Response;
class MyWelcomeController extends BaseWelcomeController
{
public function sendPasswordSavedResponse(): Response
{
return redirect()->route('home');
}
} Customizing the notificationBy default the use Illuminate\Notifications\Messages\MailMessage;
class MyCustomWelcomeNotification extends WelcomeNotification
{
public function buildWelcomeNotificationMessage(): MailMessage
{
return (new MailMessage)
->subject('Welcome to my app')
->action(Lang::get('Set initial password'), $this->showWelcomeFormUrl);
}
} To use the custom notification you must add a method called public function sendWelcomeNotification(\Carbon\Carbon $validUntil)
{
$this->notify(new MyCustomWelcomeNotification($validUntil));
} Validating extra fieldsThe default welcome form that ships with this package only asks for a password. You can add more fields to the form by publishing the view and adding more fields to it. To validate new fields you can override the class MyWelcomeController extends BaseWelcomeController
{
public function rules()
{
return [
'password' => 'required|confirmed|min:6',
'job_title' => 'required',
];
}
} Testingcomposer test ChangelogPlease see CHANGELOG for more information on what has changed recently. ContributingPlease see CONTRIBUTING for details. SecurityIf you've found a bug regarding security please mail [email protected] instead of using the issue tracker. CreditsLicenseThe MIT License (MIT). Please see License File for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论