app/Models/Project.php
use Illuminate\Database\Eloquent\Model; class Project extends Model{ // public function items() { return $this->hasManyThrough(Item::class, Board::class); }}
use Illuminate\Database\Eloquent\Model; class Project extends Model{ // public function items() { return $this->hasManyThrough(Item::class, Board::class); }}
use 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() ]); } //}