• 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

Display specific shipping method if woocommerce product has specific acf field value

How to fix bootstrap multiselect search data using ajax

api response laravel doesn't show

Applying programmatically a coupon to an Order in WooCommerce3

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

PHP Warning: Module already loaded in Unknown on line 0

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

Redis Command To Sort Keys

How to Display Data in Yajra Datatables Laravel 7?

SlimExceptionHttpNotFoundException

How to pass data to all views in Laravel 5?

How to get an Array value inside an object in an array Php [duplicate]

How to install LDAP in Docker php-fpm alpine

onKeyUp event calculation not working on the following rows from php generated forms except the first one

Laravel 5 issue with wherePivot

About Contact Privacy policy Terms and conditions