mirror of
https://github.com/10h30/Test-Eloquent-Relationships.git
synced 2026-06-05 15:07:42 +09:00
Complete all tasks
This commit is contained in:
@@ -9,7 +9,7 @@ class CountryController extends Controller
|
||||
public function index()
|
||||
{
|
||||
// TASK: load the relationship average of team size
|
||||
$countries = Country::all();
|
||||
$countries = Country::withAvg('teams', 'size')->get();
|
||||
|
||||
return view('countries.index', compact('countries'));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Project;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
@@ -11,6 +13,9 @@ class ProjectController extends Controller
|
||||
// TASK: Add one sentence to save the project to the logged-in user
|
||||
// by $request->project_id and with $request->start_date parameter
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
Auth::user()->projects()->attach($request->project_id, ['start_date' => $request->start_date]);
|
||||
|
||||
return 'Success';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$users = User::all();
|
||||
$users = User::has('projects', '>=', 1)->get();
|
||||
|
||||
return view('users.index', compact('users'));
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@ class Attachment extends Model
|
||||
|
||||
public function attachable()
|
||||
{
|
||||
// TASK: fill in the code to make it work
|
||||
return $this->morphTo(); // TASK: fill in the code to make it work
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user