Уведомить Slack отправить массив - PullRequest
0 голосов
/ 07 ноября 2018

я пытаюсь отправить некоторые значения из БД с Notify to Slack. Каким-то образом, каждый раз, когда я загружаю свой веб-сайт, я получаю только сообщение «Массив», а не данные из БД.

Это мои уведомления .php

class InventoryReStock extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($reorder)
    {
      $this->reorder = $reorder;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['slack'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toSlack($notifiable)
    {
      return (new SlackMessage)
            ->content([$this->reorder]);
    }

Это функция, которую я использую на моем контроллере для получения данных из базы данных

.
public function index()
    {
        //shows all the products in the database in an overview
        $products = Product::all()->toArray();

        $reord = Product::select('Product_Name')->where('Number_Runs', '<=', '5')->get();
        $reorder = json_decode(json_encode($reord), true);
        Notification::route('slack', 'https://hooks.slack.com/services/..../...../......')->notify(new InventoryReStock($reorder));

        return view('products.lab_inventory_overview', compact('products', 'reorder'));
    }

и это мой User.php

public function routeNotificationForSlack($notification)
   {
       Return 'https://hooks.slack.com/services/..../...../......';
   }

1 Ответ

0 голосов
/ 08 ноября 2018

Неважно, я нашел решение. Просто преобразование массива в строку заставляет его работать.

$ reorder = implode (',', array_flatten ($ reorde));

...