• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

How To Access A Column In M-M Relationship Table In Laravel

phpmysqllaravelormlaravel-9


PHP Snippet 1:

public function announcements() {
   return $this->belongsToMany(User::class, 'announcements')->withPivot('message');
}

PHP Snippet 2:

public function announcements() {
    return $this->belongsToMany(Event::class, 'announcements')->withPivot('message');
}

PHP Snippet 3:

    $ann = [];
    foreach ($event->announcements as $a) {
        $ann[] = [
            "name" => $a->name,
            "announcement" => $a->pivot->message,
            "created_at" => $a->pivot->created_at,
        ];
    }

PHP Snippet 4:

$event->announcements->pivot->message;

Related Snippets

woocommerce get_order_report_data to show order_item_id

file_put_content...fail to open stream:Permission denied in Laravel 5

Sentry + Laravel: how to log an already catched Exception?

How can I stop a symfony process which is listening on http://127.0.0.1:8000

Symfony there are no commands defined in the "make" namespace

carbon generated datetime not stored correctly into the database

How to convert a carbon into string, to take the date only?

How in Laravel run JavaScript code stored in php variable?

renameColumn migration fails for existing column with columns does not exist error

Laravel Nova, route not found

Laravel lang slug in url

how to sort by a custom appended relation to model

Laravel/ PHP: Order By Alphabetical with numbers in order [duplicate]

how to search for a file with php

Laravel dosen't connect with Oracle

About Contact Privacy policy Terms and conditions