I am really sorry but this is all so new and hard to grasp. I have read and tried but I cannot get it to work.
Here is my model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Customers extends Model
{
use HasFactory;
protected $guarded = [];
public function user() {
return $this->belongsTo(User::class);
}
public function contracts() {
return $this->hasMany(Contracts::class);
}
}
Here is the method in the Controller:
public function contracts(Customers $customer) {
return view('contracts.index', ['contracts' => $customer->contracts]);
}
The Route:
Route::get('/customers/{customer}/contracts', [CustomersController::class, 'contracts']);
This gets me all my contracts for a certain customer. Along with these contracts, I need the customer's info. They are connected by foreign keys Contracts/customer_id is associated with Customers/id.