How Do You Add Routes to Custom Files
Hello everyone, So I'm trying to add a new custom page where after going to the dashboard and processing a task, it navigates to a new page (i.e dashboard.php -> result.php). I saw online that I would need to make some changes to web.php file in the routes folder, but I keep running into errors with syntax or page not existing. Does anyone have resources or instructions on how to add a new custom route to a wave application? Thank you!
Hi there,
You can add a route to Wave just as you would for any other standard Laravel app.
You can do the following:
- Create a Controller:
php artisan make:controller YourController
Change YourController
with a descritive name of the thing that your controller will be doing.
- Then open the Controller file (
app/Http/Controllers/YourController.php
), and define your method, for example:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class YourController extends Controller
{
public function index()
{
return view('your-view');
}
}
-
After that create your blade view in the
resources/views
directory, make sure that it ends with .blade.php -
Then in your
routes/web.php
file add the route definition:
use App\Http\Controllers\YourController;
Route::get('/your-route', [YourController::class, 'index']);
Make sure to go through the introduction to Laravel course here:
https://devdojo.com/course/laravel-7-basics
And also check out the documentation here:
https://laravel.com/docs/9.x/routing
Let me know if you have any questions.