Laravel — P20: Routing Methods and Redirects

A Guide to Routing Techniques and Redirect Strategies

For this article, we’re going to stay in our comfort zone. Even though we haven’t looked at the artisan command yet, used Controllers, Models, etc, there was still enough content to write 19 other articles. There are going to be a few more written before we get to it. Nice and easy steps.

This time, I want to explain our routes/web.php file a little further and the kind of stuff that we can do there. We have been using our router as our controller as well for many instances. I love the separation of logic but I strongly feel that you should see it done the semi-wrong way first before you can gain the appreciation of Models and Controllers.

The Basics

We’ve seen our routes in action. When a user visits a URL, they’re directed to the web.php route file and the router directs the user to the data that they need to receive. For example, here are a few routes from the past couple of articles.

<?php
Route::get('/component-layout-prep', function() {
    return view('layouts-test/index', [
        'title' => 'Component Layout',
    ]);
});

Route::get('/component-layout', function() {
    return view('home/index', [
        'title' => 'Component Layout',
    ]);
});

Route::get('/component-layout/contact', function() {
    return view('contact/index', [
        'title' => 'Component Layout - Contact',
    ]);
});
If you need a full recap on the basics, check out the earlier article that I wrote on this.

Laravel Series

Continue your Laravel Learning.

Laravel — P19- Component Layouts

Actually Creating the Layout

Laravel – P19: Component Layouts

Believe it or not, the difficult part was covered in the previous article. Breaking apart the header and footer components was a tedious task. Creating a layout is simple.

Laravel Routing Methods and Redirects

A Guide to Routing Techniques and Redirect Strategies

Laravel — P20: Routing Methods and Redirects

I want to explain our routes/web.php file a little further and the kind of stuff that we can do there. We have been using our router as our controller as well for many instances.

Laravel — P21: Artisan Intro and Route List

Laravel Essentials: Exploring Artisan and Navigating Routes

Laravel — P21: Artisan Intro and Route List

Dive into Laravel with an intro to Artisan commands & route listing. Streamline your workflow & enhance app structure efficiently.

Leave a Reply