BurgerPedia: A Complete Laravel 5 and AngularJS Tutorial with Bootstrap to Make it Pretty – Part 11

in AJAX/HTML/CSS/jQuery/Javascript/Laravel/PHP/Tutorials & Samples/Web Development

Tutorial Conclusion

That basically wraps-up the tutorial. We now have a working web application that features a Laravel backend along with a AngularJS frontEnd. We have als covered many of the important topics that we set out to cover during the tutorial introduction. So now, we can talk about what we can do to make this application better. Because, although I have put this application in the tutorials section of my site, it is far from being a prodcution-ready application. Here are a couple of additional adjustments that we could make to make the application better.

Better Validation

In our application, the validation logic is done independently inside each controller. We are repeatedly calling the validation logic over and over in each controller. Worst still, it is possible to make a typo or accidentally change the validation logic in one of the controllers. That’s why it would make more sense to have a centralized validation method that all controllers use. This way, any new valuation change needs to only be done in one section of our code instead of every single controller method. Laravel offers very good ways to centralize the validation logic. This is something that can really improve our code efficiency.

Testing our Laravel Application

Laravel does a very good job of incorporating test tools into the framework. This is perfect for automated testing. We will go ahead and write a simple automated test for verifying that our route is working properly. We will go ahead and create a brand new test called HamburgerTest using artisan. To do so, type the following command:

php artisan make:test HamburgerTest

In your Laravel folders structure, there is a subfolder called tests. This folder will now contain a file called HamburgerTest.php. It contains another file called ExmapleTest.php which does a basic test to make sure that whenever the test engine visits the root path, it sees the Laravel 5 view.

We will add another test in HamburgerTest.php to test the hamburgers_api route. The test will make sure that we get an OK response from the server. (in other words, was the status code 200.) Here is the content of the file now:

public function testHamburgersList()
    {
        $this->get(route('hamburgers/'))
             ->assertResponseOk();
    }

To run your tests, simply run phpunit on the command line to run your tests.:

phpunit

Now, I am still new at Laravel’s testing capabilities so this will have to be an additional improvement for another time.

That basically wraps-up the tutorial. Hope you’ve enjoyed and let me know if you have any improvements/suggestions.

Previous Step: AngularJS Modules Controllers and Templates

Tutorial Contents
Tutorial Resources

Mifty Yusuf is a Montreal-based software developer who enjoys playing with new web technologies as well as comic books and illustrations. He beleives that, no matter what the question is, the answer is always Batman!

3 Comments

Leave a Reply

Your email address will not be published.

*

Latest from AJAX

Go to Top