• 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

Insert And Retrieve Data in MySQL with $.post Noob Question

How can I get a div content in php

Call to a member function givePermissionTo() on null

Combining a describing and one array with data

How to auto populate preferredCountries from intl-tel-input with db output

codeigniter 4 running error first time with xampp

Exact alternate to mcrypt_encrypt in PHP 7.2

I want to store data in new index as per my key in php [duplicate]

(Cache::lock()) -> get() -- Under what conditions does it return false?

get attribute from class not working php 7

Laravel dosen't connect with Oracle

Laravel with App Engine Standard Class 'FacadeIgnitionIgnitionServiceProvider' not found

php code to send checkbox form results to email

Insert a DIV after the 6th product only once in WooCommerce category archives

Passing a boolean value from checkbox in Laravel form

About Contact Privacy policy Terms and conditions