// First way ->with()return view('index') ->with('projects', $projects) ->with('tasks', $tasks) // Second way - as an arrayreturn view('index', [ 'projects' => $projects, 'tasks' => $tasks ]); // Third way - the same as second, but with variable$data = [ 'projects' => $projects, 'tasks' => $tasks];return view('index', $data); // Fourth way - the shortest - compact()return view('index', compact('projects', 'tasks'));
Enjoyed This Tip?
Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.
Recent Courses on Laravel Daily
[NEW] Laravel Boost: Deeper Practical Dive
8 lessons
32 min
Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks
7 lessons
43 min read
AI Agents/IDEs for Laravel: May 2026 (Claude Code, Codex, OpenCode, etc)
7 lessons
52 min