<?php
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 } }
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!