I was tried to find the problem, but still not found what is wrong on my code. Can anybody help what is wrong on my code.
route (web.php)
Route::get('/pegawai','PegawaiController@index');
PegawaiController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class PegawaiController extends Controller
{
public function index()
{
//mengambil data dari table pegawai
$pegawai = DB::table('pegawai')->get();
// mengirim data pegawai ke view index
return view('index',['pegawai' =>$pegawai]);
}
}
My database is using mysql and for another program is can run just for this is 404 not Found. I'm using laravel 8.6
And I tried to create new project and is no problem, but on existing project is always 404 Not Found
Any idea why this happen??
CodePudding user response:
if you are using the latest version of laravel, then you should use the path of laravel in route like ---
Route::get('/pegawai',[\App\Http\Controllers\PegawaiController,'index']);
if show some error please remove \ in the controller path.
Hope it works for you.
CodePudding user response:
I was solved this case,
just code on command prompt php artisan route:cache
and then my code is work
CodePudding user response:
You should contain the namespace in Route::get
facade function second parameter.
AS-IS
Route::get('/pegawai','PegawaiController@index');
TO-BE
Route::get('/pegawai','App\Http\Controllers\PegawaiController@index');
or
use App\Http\Controllers\PegawaiController;
Route::get('/pegawai', PegawaiController::class);
CodePudding user response:
change route to :
Route::get('/pegawai', [PegawaiController::class, 'index']);
and check htaccess
file exist in public folder
run php artisan cache:clear