public function store(Request $request) {
Pass::create($request->pass);
return redirect()->route('home');
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
class Pass extends Model
{
use HasFactory;
protected $fillable = [
'title',
'user_id',
'source',
'category_id',
];
public function setUserIdAttribute()
{
$this->attributes['user_id'] = Auth::user()->id;
}
public function user() {
return $this->hasOne(User::class,'id', 'user_id');
}
public function category() {
return $this->hasOne(Category::class,'id', 'category_id');
}
}