2016-08-01 8 views
0

私はlaravel 5.1の初心者ですので、簡単に問題があります。ユーザーとuser_infoテーブルの間のlaravelの関係

私はuserテーブルとuser_infoテーブルを持っています。私はユーザーを作成する場合、私はuser_infoテーブルの別のレコードを作成したいと私はuser_infoレコードを取得したいが、私はこれをしないユーザーを取得します。

コードは以下のとおりです。

<?php 
namespace App; 

use Illuminate\Foundation\Auth\User as Authenticatable; 

class User extends Authenticatable 
{ 

    protected $fillable = [ 
     'name', 'email', 'password', 
    ]; 

    protected $hidden = [ 
     'password', 'remember_token', 
    ]; 

    public function profile() 
    { 
     return $this->hasOne('Http\Models\userInfo'); 
    } 
} 

これは

<?php 

namespace App\Http\Models; 

use Illuminate\Database\Eloquent\Model; 

class userInfo extends Model 
{ 
    protected $table = 'user_info'; 
} 

のUserInfoクラスですこれは私がこのエラーに私が間違っているの

FatalErrorException in Model.php line 740: 
Class 'Http\Models\userInfo' not found 

を得た

@extends('master') 

@section('content') 
<div class="container"> 
    <div class="row"> 
     <div class="col-md-10 col-md-offset-1"> 
      <div class="panel panel-default"> 
       <div class="panel-heading">Welcome</div> 

       <div class="panel-body"> 
        <pre>{{ dd(Auth::user()->profile) }}</pre> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 
@endsection 

ウェルカムページですか?

+0

変更 '返します$ this-> hasOneの( 'のHttp \モデル\ USERINFO')によって

return $this->hasOne('Http\Models\userInfo'); 

;' 'へ戻るます$ this-> hasOneの(のUserInfo ::クラス) ; ' – ishadif

+0

@ishadifそれは仕事です:)。どうもありがとうございます 。私はそれらの1つのようなものを学びたいと思っています。私はユーザーモデルを作りたいのですが、どうすればいいのですか? – Hanik

+0

あなたはユーザーモデルを作りたいと思っていますか?あなたが雄弁なモデルを扱っている場合、https://laravel.com/docs/5.2/eloquentがこれを開始します。雄弁なモデル関係のためhttps://laravel.com/docs/5.2/eloquent-relationships – ishadif

答えて

0

名前空間の不一致が原因です。ただ、置き換え:

return $this->hasOne('App\Http\Models\userInfo'); 
+0

ほとんど正しいと思われますが、 'App \ Http \ Models \ userInfo'が必要です – user3158900

+0

@ user3158900ありがとう、ありがとうすぐに私に知らせる。 – motia

関連する問題