Home > Back-end >  How do i make a Laravel web.php route work on a new project?
How do i make a Laravel web.php route work on a new project?

Time:01-25

sorry for my english. I'm trying to create a laravel route but i just can't make it work. My project name is "portalRAG". It's a web app. When i access "my.address/PortalRAG" it works just fine, but i can't make any other route work.

This is a new Laravel Project. It's almost empty and i haven't touched any major configuration other than creating some 1 or 2 views,controllers and model and only created some html code. Here's my web.php file:

  <?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers;
use App\Http\Controllers\ragController\ragHomeController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('login');
});

/* NOT WORKING
Route::get('test', function () {
    return view('login');
});
 */

 Route::get('test','App\Http\Controllers\ragController\ragHomeController')->name('test');

I simply want to access "test" route. The controller i'm trying to use it's called ragHomeController and it's inside a ragController (a folder inside the basic Controller file).

Here's ragHomeController.

<?php

namespace App\Http\Controllers\ragController;

use App\Http\Controllers\Controller;
use App\Models\ragModel\ragHomeModel;
use Illuminate\Http\Request;

class ragHomeController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
       echo("WHATEVER");
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\ragModel\ragHomeModel  $ragHomeModel
     * @return \Illuminate\Http\Response
     */
    public function show(ragHomeModel $ragHomeModel)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\ragModel\ragHomeModel  $ragHomeModel
     * @return \Illuminate\Http\Response
     */
    public function edit(ragHomeModel $ragHomeModel)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\ragModel\ragHomeModel  $ragHomeModel
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, ragHomeModel $ragHomeModel)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\ragModel\ragHomeModel  $ragHomeModel
     * @return \Illuminate\Http\Response
     */
    public function destroy(ragHomeModel $ragHomeModel)
    {
        //
    }
    public function __invoke()
    {
    }
}

What i'm getting wront? i have tried clearing cache, clearing route cache, and nothing works. How should i access my "test" route? (I have tried every way and i still can't make it work). "my.address/PortalRAG/test"? "my.address/test"?

CodePudding user response:

please write you route like below

 Route::get('test',[ragHomeController::class,'Your_Method_Name'])->name('test');

and import your controller in top of your web

use App\Http\Controllers\ragHomeController;

Note:sometime it won't work so you have to run

php artisan optimize

if you are using xampp to run your laravel project then you can access your route like below

"my.address/PortalRAG/public/test"

CodePudding user response:

you didn't use the method that located in ragHomeController so write it in this way

Route::get('test',[App\Http\Controllers\ragController\ragHomeController::class, 'index'])->name('test');

now open your route like this:

my.address/PortalRAG/test

  • Related