Русское сообщество разработки на PHP-фреймворке Laravel.
Ты не вошёл. Вход тут.
Страницы 1
Создаю обратную связь, все работает кроме одного. Не могу отправить какие либо данные о пользователя почтой, просто письмо без проблем, вместе с данными никак.
Это контроллер, который сохраняет данные о пользователе и вызывает очередь для отправки письма
$declaration = new Declarations();
$declaration -> name_declaration = $request -> name_declaration;
$declaration -> users_id = Auth::user()->id;
$declaration -> declaration = $request -> declaration;
if ($request->file('url_image') != null){ //если есть картинка,
$path = $request->file('url_image')->store('images'); //то загрузить в images
$declaration -> url_image = asset('storage/app/'.$path);
}
$declaration->save(); //охранить в свойства обьекта
$data_message = $declaration;//$request -> all();
SendMail::dispatch($data_message); //-> delay(now()->addMinutes(1)); //отправка письма спустя ? минуты
//return $declaration->User->find($declaration -> users_id)->name;
return $declaration->url_image;
Здесь представлена очередь.
class SendMail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 10;
protected $data_message;
/**
* Create a new job instance.
*
* @param $data
*/
public function __construct($data)
{
$this -> data_message = $data;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Mail::send('mail.mail', $this -> data_message, function ($message) { //письмо
$message -> to('declarationpo4ta@gmail.com', 'to declaration') -> subject('Declaration'); //кому
$message -> from('declarationpo4ta@gmail.com','declaration'); //от кого
});
}
}
Это представление
<h1>{{ $data_message['name_declaration'] }}</h1>
Это ошибка
ErrorException: Undefined variable: data_message in C:\Laravel learn\Sign IN UP\storage\framework\views\dc01eec9ed12360ccda114273762431c5d4144d9.php:4
Stack trace:
#0 C:\Laravel learn\Sign IN UP\storage\framework\views\dc01eec9ed12360ccda114273762431c5d4144d9.php(4): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined varia...', 'C:\\Laravel lear...', 4, Array)
#1 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\Engines\PhpEngine.php(43): include('C:\\Laravel lear...')
#2 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\Engines\CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('C:\\Laravel lear...', Array)
#3 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\View.php(142): Illuminate\View\Engines\CompilerEngine->get('C:\\Laravel lear...', Array)
#4 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\View.php(125): Illuminate\View\View->getContents()
#5 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\View.php(90): Illuminate\View\View->renderContents()
#6 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(353): Illuminate\View\View->render()
#7 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(326): Illuminate\Mail\Mailer->renderView('mail.mail', Array)
#8 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(244): Illuminate\Mail\Mailer->addContent(Object(Illuminate\Mail\Message), 'mail.mail', NULL, NULL, Array)
#9 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(237): Illuminate\Mail\Mailer->send('mail.mail', Array, Object(Closure))
#10 C:\Laravel learn\Sign IN UP\app\Jobs\SendMail.php(39): Illuminate\Support\Facades\Facade::__callStatic('send', Array)
#11 [internal function]: App\Jobs\SendMail->handle()
#12 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array)
#13 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#14 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#17 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\SendMail))
#18 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(104): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\SendMail))
#19 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#20 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(49): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendMail), false)
#21 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#22 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(337): Illuminate\Queue\Jobs\Job->fire()
#23 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(283): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#24 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#25 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(102): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#26 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#27 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#28 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array)
#29 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#30 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#31 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#32 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Console\Command.php(183): Illuminate\Container\Container->call(Array)
#33 C:\Laravel learn\Sign IN UP\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#34 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Console\Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#35 C:\Laravel learn\Sign IN UP\vendor\symfony\console\Application.php(921): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 C:\Laravel learn\Sign IN UP\vendor\symfony\console\Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 C:\Laravel learn\Sign IN UP\vendor\symfony\console\Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Console\Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 C:\Laravel learn\Sign IN UP\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#41 {main}
Next ErrorException: Undefined variable: data_message (View: C:\Laravel learn\Sign IN UP\resources\views\mail\mail.blade.php) in C:\Laravel learn\Sign IN UP\storage\framework\views\dc01eec9ed12360ccda114273762431c5d4144d9.php:4
Stack trace:
#0 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\Engines\PhpEngine.php(45): Illuminate\View\Engines\CompilerEngine->handleViewException(Object(ErrorException), 0)
#1 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\Engines\CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('C:\\Laravel lear...', Array)
#2 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\View.php(142): Illuminate\View\Engines\CompilerEngine->get('C:\\Laravel lear...', Array)
#3 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\View.php(125): Illuminate\View\View->getContents()
#4 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\View\View.php(90): Illuminate\View\View->renderContents()
#5 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(353): Illuminate\View\View->render()
#6 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(326): Illuminate\Mail\Mailer->renderView('mail.mail', Array)
#7 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(244): Illuminate\Mail\Mailer->addContent(Object(Illuminate\Mail\Message), 'mail.mail', NULL, NULL, Array)
#8 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(237): Illuminate\Mail\Mailer->send('mail.mail', Array, Object(Closure))
#9 C:\Laravel learn\Sign IN UP\app\Jobs\SendMail.php(39): Illuminate\Support\Facades\Facade::__callStatic('send', Array)
#10 [internal function]: App\Jobs\SendMail->handle()
#11 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array)
#12 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#13 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#14 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#15 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#16 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\SendMail))
#17 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(104): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\SendMail))
#18 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#19 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(49): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendMail), false)
#20 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#21 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(337): Illuminate\Queue\Jobs\Job->fire()
#22 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(283): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#23 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#24 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(102): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#25 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#26 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#27 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array)
#28 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#29 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#30 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Container\Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#31 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Console\Command.php(183): Illuminate\Container\Container->call(Array)
#32 C:\Laravel learn\Sign IN UP\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#33 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Console\Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#34 C:\Laravel learn\Sign IN UP\vendor\symfony\console\Application.php(921): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 C:\Laravel learn\Sign IN UP\vendor\symfony\console\Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 C:\Laravel learn\Sign IN UP\vendor\symfony\console\Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Console\Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 C:\Laravel learn\Sign IN UP\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 C:\Laravel learn\Sign IN UP\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 {main}
Так же сделал чтобы после множества не удачных попыток, очередь сохраняла отчет в бд.
Уже часа 3 перепробовал все что смог самостоятельно. Плииз спасите...
Не в сети
Почему не используешь Notifications из коробки ?
Не в сети
Потому что я новичок и не шарю((
Проблема не актуальна, решена. Все заработало после отчистки кэша и конфига (php artisan config:clear, php artisan cache:clear), перезапуска очереди php artisan queue:work . Если не сложно дай сыль где можно узнать про то что ты сказал.
Может кому полезно будет.
Изменено Kronk (16.08.2019 18:44:36)
Не в сети
https://laravel.com/docs/master
там всё. ну почти всё.
Не в сети
Страницы 1