Hi transpalette and thank you very much for your reply! You have given me a couple of ideas but I don't believe this is a solution to my problem, it's my fault for not explaining properly. I realise there should not be an activation column in the pivot table and wish to remove it. It is a many-to-many as any of the displays can be activated by any of the users. I'm also pretty certain my pivot table is set up correctly as is functioning as it should, although I will show some code . So this is my display model.
class Display extends Model
{
public function customers(){
return $this->belongsToMany(Customer::class)->withTimestamps()->withPivot('activations');
}
}
This is my Customer model
class Customer extends Model
{
protected $fillable = [
'name', 'email',
];
public function displays(){
return $this->belongsToMany(Display::class)->withTimestamps()->withPivot('activations');
}
}
Here is my Display controller
class DisplayController extends Controller
{
public function __construct(){
$this->middleware('admin2');
}
public function index(){
//finding all displays from database
$displays = Display::all();
//sending the results to the view
return view('displays.displays', compact('displays'));
}
public function show(Display $display){
//eager loading the customers linked to the display
$display->load('customers');
//sending the single display and it's linked customers to the view
return view('displays.show',compact('display'));
}
}
And this is the show view
@extends('layouts.app')
@section('content')
<h1>{{$display->location}}</h1>
<ul>
@foreach($display->customers as $customer)
<a href ="../customers/{{$customer->id}}"> <li><p>Customer: {{$customer->name}} Activations:{{$customer->pivot->activations}} </p></li></a>
@endforeach
</ul>
@endsection
As you can see the Activation count is currently getting the data from the activation's column in the pivot table which I know is incorrect. I wish to remove the activation column altogether and simply count the amount of times that the matching foreign keys appear in the pivot table. So if a customer with id 2 activates a display with id 6 twice, then I can call a function that can count that.