mirror of
https://github.com/10h30/Test-Eloquent-Relationships.git
synced 2026-07-11 10:46:13 +09:00
Task 3 - multi-level relationships
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function show(User $user)
|
||||
{
|
||||
return view('users.show', compact('user'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['task_id', 'name', 'comment'];
|
||||
|
||||
public function task()
|
||||
{
|
||||
return $this->belongsTo(Task::class);
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,12 @@ class User extends Authenticatable
|
||||
|
||||
public function tasks()
|
||||
{
|
||||
// TASK: fix this by adding a parameter
|
||||
return $this->hasMany(Task::class);
|
||||
}
|
||||
|
||||
public function comments()
|
||||
{
|
||||
// TASK: add the code here for two-level relationship
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user