Skip to content

Commit

Permalink
9 Tasks Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
azampanda committed Nov 8, 2023
1 parent f9345a8 commit 15d7504
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/CountryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 as teams_avg_size', 'size')->get();

return view('countries.index', compact('countries'));
}
Expand Down
9 changes: 8 additions & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ public function store(Request $request)
{
// TASK: Add one sentence to save the project to the logged-in user
// by $request->project_id and with $request->start_date parameter

auth()->user()->projects()->attach(
// target project
$request->project_id,
// additional data
[
'start_date' => $request->start_date,
]
);
return 'Success';
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UserController extends Controller
{
public function index()
{
$users = User::all();
$users = User::has('projects')->get();

return view('users.index', compact('users'));
}
Expand Down
1 change: 1 addition & 0 deletions app/Models/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class Attachment extends Model
public function attachable()
{
// TASK: fill in the code to make it work
return $this->morphTo();
}
}
5 changes: 5 additions & 0 deletions app/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public function task()
{
return $this->belongsTo(Task::class);
}

public function user()
{
return $this->belongsTo(User::class);
}
}
2 changes: 1 addition & 1 deletion app/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Role extends Model
public function users()
{
// TASK: fix this by adding a parameter
return $this->belongsToMany(User::class);
return $this->belongsToMany(User::class, 'users_roles');
}
}
2 changes: 1 addition & 1 deletion app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Team extends Model
public function users()
{
// TASK: fix this by adding some extra code
return $this->belongsToMany(User::class);
return $this->belongsToMany(User::class, 'team_user', 'pivot');
}

}
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ class User extends Authenticatable
public function tasks()
{
// TASK: fix this by adding a parameter
return $this->hasMany(Task::class);
return $this->hasMany(Task::class, 'users_id');
}

public function comments()
{
// TASK: add the code here for two-level relationship
return $this->hasMany(Comment::class, 'users_id');
}

public function projects()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('comments', function (Blueprint $table) {
$table->unsignedBigInteger('users_id')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('comments', function (Blueprint $table) {
//
});
}
};
8 changes: 5 additions & 3 deletions resources/views/tasks/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<ul>
@foreach ($tasks as $task)
<li>{{ $task->name }} ({{ $task->user->name }})</li>
@endforeach
@forelse ($tasks as $task)
<li>{{ $task->name }} ({{ $task->user->name ?? ' ' }})</li>
@empty
<li>{{__('No data available')}}
@endforelse
</ul>

0 comments on commit 15d7504

Please sign in to comment.