Book Image

Laravel Application Development Blueprints

By : Arda Kılıçdağı, Halil İbrahim Yılmaz
Book Image

Laravel Application Development Blueprints

By: Arda Kılıçdağı, Halil İbrahim Yılmaz

Overview of this book

<p>Laravel is a clean and classy framework for PHP web development. It helps you to create wonderful applications using simple, expressive syntax. Development should be a creative and enjoyable experience, not something that is painful, and Laravel makes it enjoyable for the users. Laravel's directory structure is designed to be familiar to users of other popular PHP frameworks. Web applications of any shape or size can easily be created using this structure similar to the way that they would be created in other frameworks. With the recently released 4th Version, Laravel became even better in numerous ways. Within this book, we will help you learn about both the old and new features of Laravel while developing various applications.</p> <p>Laravel Application Development Blueprints covers how to develop 10 different applications step-by-step using Laravel 4. You will also learn about both basic and advanced usage of Laravel’s built-in methods, which will come in handy for your project. Also, you will learn how to extend the current libraries with the built-in methods and include third-party libraries.</p> <p>This book looks at the Laravel PHP framework and breaks down the ingrained prejudice that coding with PHP causes due to spaghetti code. It will take you through a number of clear, practical applications that will help you to take advantage of the Laravel PHP framework and PHP OOP programming whilst avoiding spaghetti code.</p> <p>You'll also learn about creating secure web applications using different methods such as file uploading and processing, making RESTful AJAX requests, and form processing. If you want to take advantage of the Laravel PHP framework's validate, file processing, and RESTful controllers in various types of projects, then this is the book for you.<br />Everything you need to know to code fast and secure applications with the Laravel PHP framework will be discussed in this book.</p>
Table of Contents (17 chapters)
Laravel Application Development Blueprints
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Validating and processing the form


In this section, we will validate the submitted form and ensure that the fields are valid and the required fields are filled. Then we will save the data to the database.

  1. First, we need to define the form validation rules. We prefer adding validation rules to the related model, so the rules become reusable, and this prevents the code from becoming bloated. To do this, add the following code in feeds.php located at app/models/ (the model that we generated earlier in this chapter), inside the class definition before the last }:

    //Validation rules
    public static $form_rules = array(
      'feed'    => 'required|url|active_url',
      'title'  => 'required'
      'active'  => 'required|between:0,1',
      'category'  => 'required| in:News,Sports,Technology'
    );

    We set the variable as public, so it can be used outside the model's file itself, and we set it to static, so we can directly access the variable.

    We want the feed to be a URL, and we want to check whether it's...