Task 8 - belongstomany add

This commit is contained in:
PovilasKorop
2021-11-22 11:46:59 +02:00
parent fc0bf0d079
commit a114584904
8 changed files with 129 additions and 1 deletions
@@ -0,0 +1,16 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProjectController extends Controller
{
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
return 'Success';
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use HasFactory;
protected $fillable = ['name'];
}
+5
View File
@@ -52,4 +52,9 @@ class User extends Authenticatable
{
// TASK: add the code here for two-level relationship
}
public function projects()
{
return $this->belongsToMany(Project::class)->withPivot('start_date');
}
}