这是我的职位表试图让非对象的财产laravel 5.2
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration
{
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->integer('prf_id')->unsigned();
$table->foreign('prf_id')->references('id')->on('profiles')->onDelete('cascade');
$table->longText('status');
$table->timestamps();
});
}
public function down()
{
Schema::drop('posts');
}
}
这是我的Post模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $table='posts';
protected $fillable = ['status'];
protected $hidden = [];
public function profile(){
return $this->belongsTo('App\Profile');
}
public function user(){
return $this->belongsTo('App\User');
}
}
这是剖面模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
protected $table='profiles';
protected $fillable = ['user_id','name','position','roles','username','college','phone','location','graduation','skill'];
protected $hidden = [];
public function posts(){
return $this->hasMany('App\Post');
}
}
这是用户模式
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
protected $fillable = [
'fname','lname', 'email','sex', 'password','user_id','roles'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function posts(){
return $this->hasMany('App\Post');
}
}
当我尝试{{$状态 - >用户> FNAME}} this.its显示正确的值,但是当我尝试{{$状态 - >尝试获取非对象的属性(视图:C:\ xampp \ htdocs \ abc \ resources \ views \ pages \ profile.blade.php) i真的不知道为什么:(
显示代码取出'$ status'的位置? –
'public function myprofile(Request $ request){ $ id = $ request-> prf; $ user = User :: where('id','=',$ id) - > first(); $ u_id = $ user-> user_id; $ all = Profile :: where('id','=',$ id) - > first(); $ tasks = Task :: where('user_id','=',$ u_id) - > get(); $ user = User :: where('id','=',$ id) - > first(); $ statuses = Post :: all(); return view('pages.profile',compact('all','tasks','user','status')); } ' – leo
@leo作为编辑问题请。 – apokryfos