3

I was making a small blog site, but got this error. Is there anyone who can help? Currently, my homepage page that I defined in view is not working. My homepage.blade.php page, by the way, inside the front folder is homepage.blade.

my web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Front\HomeController;


Route::get('/',"HomeController@index");


-----------------------------------------------

here is my controller

<?php

namespace App\Http\Controllers\Front;
use App\Http\Controllers\Front\HomeController;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Category;

class HomeController extends Controller
{
    public function index(){

        $data['categories']=Category::inRandomOrder()->get();
 
       return view('front.layouts.homepage',$data);
     }
}



2
  • 1
    Please share your code not image Commented Jul 29, 2021 at 11:37
  • sorry, i will share the code next time. Commented Jul 29, 2021 at 12:24

2 Answers 2

1

You have to use like below code

Route::get('/', [HomeController::class, 'index']);
Sign up to request clarification or add additional context in comments.

8 Comments

Now I'm getting this error, Class "App\Http\Controllers\Front\Category" not found
You have to use use App\Models\Category in the header section in HomeController
I have a homepage.blade.php page in View. But I got such error. "View [front.homepage] not found"
You have to use return view('front. homepage',compact('data'))
I defined in Controller but it didn't work. :(
|
0

I think you should do like this -

Route::get('/','Front\HomeController@index');

because You have directory like App\Http\Controllers\Front\HomeController. and you can't call without calling the exact path. hope, It helps.

8 Comments

I tried this, I typed the full folder path, but it was didnt work.
plz update the queston, with code , in picture its truly blurr
plz attach controller also, so that we can see.
I fixed my question and removed the pictures.
dude, you can't call the controller in the same file where you are working in the same controller
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.