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 log in with admin access, it gives me the following error
InvalidArgumentException
View [admin.home] not found.
http://127.0.0.1:8000/home
While I created a folder called admin in the views folder, and I created a file called home.blade.php in it.
views\admin\home.blade.php
But if I log in with user access, the home.blade.php file I created in the user folder, which is in the views folder, will be displayed without error.
What can I do?
Thanks for taking the time to read this question.
CodePudding user response:
Try to name the route like this:
Route::get('/home',[HomeController::class,'redirect'])->name('home');
then run the php artisan route:cache in the terminal
also check if the name file name has a typo or something!
CodePudding user response:
If the blade file really exists in the this path then the problem occurs by caching. Then 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 correctly path in resources\views.
