Laravel по-русски

Русское сообщество разработки на PHP-фреймворке Laravel.

Ты не вошёл. Вход тут.

#1 08.12.2015 15:46:44

алиасы в люмене

Простой пример

class_alias(Illuminate\Support\Facades\URL::class,   'URL');
class_alias(Illuminate\Support\Facades\Input::class, 'Input');
class_alias(Illuminate\Support\Facades\View::class,  'View');

прошу обратить внимание, что люмен обрезан по самые уши.
мыльницы там по умолчанию нет.

class_alias(Illuminate\Contracts\Mail\Mailer::class,  'Mailer');
class_alias(Illuminate\Contracts\Mail\MailQueue::class,  'MailQueue');

то есть всё придётся создавать самим, даже привычные обёртки.
дойдут руки - выложу пример для простой отсылки писем

Не в сети

#2 25.02.2025 15:04:56

Re: алиасы в люмене

some Facades and features are not included by default, unlike Laravel. However, you can still use them by setting up the aliases manually, as shown in your example. Here's how to configure them and get mail sending working as well.

1. Enable Facades in Lumen
In bootstrap/app.php, enable Facades by uncommenting or adding:

php
Copy
Edit
$app->withFacades();
2. Register Aliases
Add the following at the end of bootstrap/app.php:

php
Copy
Edit
class_alias(Illuminate\Support\Facades\URL::class,   'URL');
class_alias(Illuminate\Support\Facades\Input::class, 'Input');
class_alias(Illuminate\Support\Facades\View::class,  'View');
class_alias(Illuminate\Contracts\Mail\Mailer::class,  'Mailer');
class_alias(Illuminate\Contracts\Mail\MailQueue::class,  'MailQueue');
3. Configure Mailer in Lumen
Unlike Laravel, Lumen doesn’t come with a built-in mail configuration. You need to:

Install the mail package:
bash
Copy
Edit
composer require illuminate/mail
Register the service provider in bootstrap/app.php:
php
Copy
Edit
$app->register(Illuminate\Mail\MailServiceProvider::class);
Set up mail configuration in .env:
env
Copy
Edit
MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=example@example.com
MAIL_FROM_NAME="Example App"
In config/mail.php (create the file if it doesn’t exist):
php
Copy
Edit
return [
    'default' => env('MAIL_MAILER', 'smtp'),
    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
        ],
    ],
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
];
Make sure to load the configuration in bootstrap/app.php:

php
Copy
Edit
$app->configure('mail');
4. Sending Mail Example
In your controller, use the Mailer facade to send an email:

php
Copy
Edit
use Mailer;

public function sendEmail()
{
    Mailer::send([], [], function ($message) {
        $message->to('recipient@example.com')
                ->subject('Test Email')
                ->setBody('<h1>Hello, this is a test email!</h1>', 'text/html');
    });

    return 'Email sent!';
}

Не в сети

Подвал раздела