troubleshooting Question

What Are "Requests" in Laravel?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
LaravelPHP
3 Comments2 Solutions68 ViewsLast Modified:
I'm working through a Laravel tutorial and it references "Requests." I followed along and I created a "CreatePage.php" file in a brand new "Requests" folder and it looks like this:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CreatePage extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required', 
			'body' => 'required'
        ];
    }
}

Does this need to be cited in a Controller or a Model? I ask because the "rules" seem to imply that if my user doesn't include a value for either the name of the body columns, then they're going to get an error. That error doesn't show up.

What are "requests" and how do they need to be referenced so the rules actually apply?
ASKER CERTIFIED SOLUTION
David Favor
Fractional CTO
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros