I'm just a beginner at laravel, Sorry if it's a stupid question
Here's my controller :-
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use App\Profile;
use Auth;
class ProfilesController extends Controller
{
public function _construct()
{
$this->middleware('auth');
}
public function create()
{
return view('bio');
}
public function store(Request $request)
{
auth()->user()->profile()->user_id;
// create Bio
$profile = new Profile;
$profile->bio = $request->input('bio');
$profile->save();
return redirect('/home');
}
}
Here's My Model:-
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
protected $gaurded = [];
protected $fillable = ['user_id', 'bio'];
public function user()
{
return $this->belongsTo(User::class);
}
}
Here Are My Tables
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
protected $gaurded = [];
protected $fillable = ['user_id', 'bio'];
public function user()
{
return $this->belongsTo(User::class);
}
}
Here's My User Model:-
public function profile()
{
return $this->hasOne(Profile::class);
}
public function posts()
{
return $this->hasMany(Posts::class);
}
I'm getting this error "Undefined property: Illuminate\Database\Eloquent\Relations\HasOne::$user_id" I don't know where i went wrong please help me and guide me if u can Thanks
$gaurded
. What isauth()->user()->profile()->user_id;
supposed to do? – brombeerauth()->user()->profile->user_id;
instead ofauth()->user()->profile()->user_id;
– TsaiKoga$id = auth()->id();
– TsaiKoga