mirror of
https://github.com/10h30/Test-Eloquent-Relationships.git
synced 2026-07-11 10:46:13 +09:00
Task 1 - hasmany incorrect
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TaskController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
{
|
||||
// TASK: find out why this sentence fails, and fix it in Eloquent Model
|
||||
auth()->user()->tasks()->create([
|
||||
'name' => $request->name
|
||||
]);
|
||||
|
||||
return 'Success';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Task extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name', 'users_id'];
|
||||
}
|
||||
@@ -41,4 +41,9 @@ class User extends Authenticatable
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function tasks()
|
||||
{
|
||||
return $this->hasMany(Task::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user