posts - Laravel Eloquent - Get Data from multiple models using one call -
i have platform allows users make 3 post types (posts, questions , debates) similar 1 have attributes in database. separated them in future can still add more columns 1 table without tearing hair. result created 3 different models called (posts, questions, debates). want able pull whole list of posts on users timeline making single call,
$posts = user::find($id)->getallposts
then return list of posts, questions , debates can loop on , display in proper datetime order.
heres posts table:
public function up() { schema::create('posts', function (blueprint $table) { $table->increments('id'); $table->integer('user_id')->unsigned(); $table->text('body'); $table->timestamps(); $table->softdeletes(); }); }
heres questions table:
public function up() { schema::create('questions', function (blueprint $table) { $table->increments('id'); $table->integer('user_id')->unsigned(); $table->text('body'); $table->timestamps(); $table->softdeletes(); }); }
heres debates table:
public function up() { schema::create('debates', function (blueprint $table) { $table->increments('id'); $table->integer('user_id')->unsigned(); $table->string('subject'); $table->text('body'); $table->timestamps(); $table->softdeletes(); }); }
Comments
Post a Comment