• 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

How to Install Composer Require doctrine/dbal

PHP echo values of all sub keys [duplicate]

hidden INPUT value not available in $_POST

I want a way to give path to my files which are outside of public folder in laravel

PHP only Hit Counter?

Mobile browsers are adding .html to filename on download

Target Individual Form Instance/Counter Inside A PHP While Loop

Using spatie/media-library, how to rename a collection of uploaded files?

How to use functions that are declared in snippets in Evolution CMS (Modx) in an external PHP Script?

I'm trying to write a clean url for my website using the $_SERVER['REQUEST_URI'] in php

Laravel eloquent update record without loading from database

How to get the ID of the link in another page in php

api response laravel doesn't show

Magento 2 - How to add new block to admin panel in product page?

Converting array to string and then back in PHP

About Contact Privacy policy Terms and conditions