我正在尝试从数据库表中搜索值并使用laravel将结果显示到网站。我的controller.php代码在这里
else
{
try
{
$pname = Input::get('pname');
$parents = ForumParent::where('pname', $pname)->first();
if(empty($parents))
{
throw new \Exception("Parent not found");}
return Redirect::route('view',$parents->paddress);
}
catch (Exception $e)
{ return "not value";
//abort(404);
}
}
}
public function view($paddress)
{
$parents=ForumParent::find($paddress);
$users=User::all();
return View::make('search.viewsearch')
->with('parents',$parents)
->with('users',$users);
}
答案 0 :(得分:0)
改变这个:
$parents = ForumParent::where('pname', $pname)->first();
到此:
$parents = ForumParent::where('pname', '=', $pname)->first();
或强>
$parents = ForumParent::where('pname','LIKE', '%' . $pname . '%')->first();
看,如果有帮助。