Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试获取laravel 5.2中非对象的属性_Php_Database_Laravel - Fatal编程技术网

Php 尝试获取laravel 5.2中非对象的属性

Php 尝试获取laravel 5.2中非对象的属性,php,database,laravel,Php,Database,Laravel,这是我的帖子表 <?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreatePostsTable extends Migration { public function up() { Schema::create('posts', function (Blueprin

这是我的帖子表

    <?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');
    }
}

在你的
帖子中
尝试以下代码:

public function profile(){
    return $this->belongsTo('App\Profile', 'prf_id');
}

显示正在获取的代码。
$status
?'public function myprofile(Request$Request){$id=$Request->prf;$user=user::where('id','=',$id)->first();$u-id=$user->user\u-id;$all=Profile::where('id','=',$id)->first();$tasks=tasks::where('user\id','=',$u-id)->get();$user=user::where('id','id','id','$statuses=Post::all();返回视图('pages.profile',compact('all','tasks','user','statuses');}'@leo作为问题中的编辑。您的数据库未使用表配置文件的de默认键,能否显示de表键id?belongsTo('App\Profile')尝试使用Profile\u id而不是prf\u id
<?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');
    }

}
public function profile(){
    return $this->belongsTo('App\Profile', 'prf_id');
}