InvalidArgumentException View [admin.home] not found. http://127.0.0.1:8000/home
I defined a route in Laravel
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
Route::get('/home', [HomeController::class, 'redirect']);
?>
Which executes the redirect function from the HomeController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
class HomeController extends Controller
{
public function redirect() {
if (Auth::id()) {
if (Auth::user()->usertype == '0') {
return view('user.home');
} else {
return view('admin.home');
}
} else {
return redirect()->back();
}
}
}
?>
Now when I login with admin access, it gives me the following error
InvalidArgumentException
View [admin.home] not found.
http://127.0.0.1:8000/home
I have created a folder called admin
in the views
folder, and I have created a file called home.blade.php
in it: views\admin\home.blade.php
.
But if I login with user access, the blade file will be displayed without errors.
What can I do?
Thanks for taking the time to read this question.
Update:
The error image is shown below
If the blade file really exists in the path then the problem occurs by caching. Open the terminal and run: php artisan view:clear
.
Make sure that your file is a blade.php
file. It often happens that blade is forgotten in the name. i.e. admin.php
.
Also make sure that the file is placed in the correct path inside resources\views
.
try php artisan optimize:clear