【发布时间】:2021-04-17 06:17:11
【问题描述】:
这是我的控制器页面
public function getsinglepost($slug)
{
$post = User::where('slug', $slug)->get();
$post_1 = DB::select('select * from user_post');
$name = request()->input('user_name');
$email = request()->input('user_email');
$question = request()->input('user_question');
return view('single')
->with('user_name',$post_1->user_name)
->with('user_email',$post_1->user_email)
->with('user_question',$post_1->user_question)
->with(['post_1'=>$post_1])
}
这是我的迁移
*/
public function up()
{
Schema::create('user_post', function (Blueprint $table) {
$table->increments('id');
$table->string('user_name',100);
$table->string('user_email',100);
$table->string('user_question',900);
$table->string('slug',900);
$table->timestamp('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('user_post');
}
}
在这里,我试图获取不同页面中单行的数据,这让我很不爽 请随意添加任何内容
【问题讨论】:
-
你想用这条线做什么
$post_1 = DB::select('select * from user_post');? -
DB::select 返回数组,而不是对象。
标签: php laravel error-handling eloquent controller