public function index($id) { //$articles=DB::table('blog_articles')->where('blog_id','=',$id)->paginate(15); if (Auth::user()->tag == 'teacher') { $user = User::find($id); $blog = $user->blog; if (empty($blog)) { # code... $blog = new Blog(); $blog->name = $user->name; $blog->user_id = $user->id; $blog->save(); } $articles = $blog->articles()->get(); $user = User::find($id); $data = array('articles' => $articles, 'user' => $user, 'blog' => $blog); //return $data; return view('blog.admin.index')->with('data', $data); } else { return '该博客暂时不对实验室外部人员开放'; } }