• 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

"There is no active transaction" when refreshing database in Laravel 8.0 test

Laravel - Browser displays message again when I press back button

PHP web3 ERC20 token function call

How to get Laravel's CSRF Token from Another Website?

php curl_exec() Connection refused when retrieving a remote image

How to disable only_full_group_by option in Laravel

Required field only if another field has a value, must be empty otherwise

Get latest Tweets - What API

How can I make good efficent AJAX live forms with just jQuery and

Attempt to read property "view" on null when sending password reset email

google content api for shopping

Saving Data from form to database using AngularJS and php

Why does codeigniter & Linux server throws unserialize() session data error when user tries to login

Submitting a form with ajax in Wordpress

How do I pass the dynamic output of a php variable or php function to a CSS variable?

About Contact Privacy policy Terms and conditions