my model in App\Models, I've added the company_id and year to be for the primary key
class CompanyMasterCuti extends Model
{
use HasFactory;
protected $table = 'company_master_cuti';
protected $fillable = [
'company_id', 'year', 'cuti', 'created', 'created_by', 'modified', 'modified_by',
];
protected $guarded = [];
protected $keyType = 'string';
public $timestamps = false;
protected $primaryKey = ['company_id', 'year'];
public $incrementing = false;
public function company() {
return $this->belongsTo('App\Models\Company', 'company_id', 'id');
}
}
my code in controller
public function show($company_id, $year) {
$master_cuti = CompanyMasterCuti::where('company_id', $request->company_id)->where('year', $request->year)->first();
return view('master-cuti.show', compact('master_cuti'));
}
my code in index.blade.php to direct to route show
@forelse($master_cuti as $m_cuti)
<a href="{{ route('master-cuti.show', [$m_cuti->company_id, $m_cuti->year] ) }}">
<i class="badge-circle badge-circle-light-secondary bx bxs-show font-medium-1 text-success"></i>
</a>
@endforelse
my code in show.blade.php
<div class="card-content">
<div class="card-body">
<ul class="list-group p-2" style="padding-top: 5px !important">
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="mr-3">Tahun</span>
<span>{{ $master_cuti->year }}</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="mr-3">Cuti</span>
<span>{{ $master_cuti->cuti}}</span>
</li>
</ul>
</div>
</div>
route
Route::resource('master-cuti', CompanyMasterCutiController::class);
I want to display data based on company_id and year which is the primary key of the table company_master_cuti . My code is not correct because I tried to return data from the controller the data is null, what's wrong with my code? is there any solution for my problem?

