-
app/Models/Project.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Project extends Model { // public function items() { return $this->hasManyThrough(Item::class, Board::class); } }
-
app/Http/Controllers/ItemController.php
Open in GitHubuse App\Models\Item; use App\Models\Project; class ItemController extends Controller { public function show($projectId, $itemId = null) { $project = null; if (!$itemId) { $item = Item::query()->where('slug', $projectId)->firstOrFail(); } else { $project = Project::query()->where('slug', $projectId)->firstOrFail(); $item = $project->items()->where('items.slug', $itemId)->firstOrFail(); } return view('item', [ 'project' => $project, 'board' => $item->board, 'item' => $item, 'user' => $item->user, 'comments' => $item->comments()->with('user:id,name,email')->oldest()->get(), 'activities' => $item->activities()->with('causer')->latest()->limit(10)->get() ]); } // }