私はこのような何かやりたい:Laravel - どのようにテーブルを変更するのか?
$posts= Status::where('users_id',$user->id)->orWhere(DB::table('user_status_share.user_id', $user->id))->orderBy('created_at', 'DESC')->get();
をしかし、私はエラーを取得しています:strtolower()は、パラメータ1は、文字列、指定されたオブジェクトであることを期待 - 私は「orWhere」でテーブルを変更する方法方法?これは可能ですか?そうでない場合 - 1つのクエリで2つのテーブルを使用する方法
スキーマ(ステータス):
public function up()
{
Schema::create('users_status', function (Blueprint $table) {
$table->increments('id')->unique();
$table->longText('status_text');
$table->integer('users_id')->unsigned();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users_status');
}
スキーマ(StatusShare):
public function up()
{
Schema::create('user_status_share', function (Blueprint $table) {
$table->increments('id');
$table->integer('status_id');
$table->integer('user_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('user_status_share');
}
モデルステータス:
namespace App\Eloquent;
use Illuminate\Database\Eloquent\Model;
class Status extends Model
{
public $timestamps = true;
protected $table = 'users_status';
protected $guarded = ['id'];
public function comments()
{
return $this->hasMany(StatusComments::class);
}
public function likes()
{
return $this->hasMany(StatusLikes::class);
}
public function shares()
{
return $this->hasMany(StatusShare::class);
}
}
モデルStatusShare:
<?php
namespace App\Eloquent;
use Illuminate\Database\Eloquent\Model;
class StatusShare extends Model
{
public $timestamps = true;
protected $table = 'user_status_share';
protected $guarded = ['id'];
public function status()
{
return $this->hasOne(Status::class);
}
}
bからデータを取得しますかothテーブル? – blablabla
あなたのスキーマ構造と期待しているデータ形式を出力に投稿してください。 –
はい、2つのテーブルからデータを取得したい – Patrick1870