qcode
  • 创作工场专业版,一问多答!更智能、更完整、更原创
  • 这是一个超强内容创作平台,它会写文章、做设计、绘图、敲代码,有问必答!
🔥点击使用-免登录深度版🔥

<?php

时间2023-03-20 15:57:24 提问来自 辽宁省沈阳市 的网友 分类创作 浏览546
namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Category; use App\Models\Product; class HomeController extends Controller { /** * Create a new controller instance. * Only guests are able to access the home page. The user is redirected to the dashboard if logged in. * @return void */ public function __construct() { $this->middleware('guest'); //redirects users who are logged in from accessing the home page. They will be redirected to their dashboard page instead. } /** * Show the application dashboard. * @return \Illuminate\Contracts\Support\Renderable */ public function index() { //this is the default index method for this controller - it will show when a user visits '/' in their browser and they are not logged in (guests) $categories = Category::all(); //fetch all categories from DB and assign them to variable so they can be used on view file (home.blade) - see line 18 of home/index blade file for more info on how this works return view('home', compact('categories')); //pass categories variable into view file (home) so they can be used on that page - see line 18 of home/index blade file for more info on how this works } }

不满意?免费深度重写!

免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。

上一篇 修复下这个PHP代码 下一篇 建设教育强国的青年力 量