0

I'm trying to reference the Requests class in Laravel, I've tried so many fixes with the keyword "use" but each time I keep getting Reflection exception that says app\path\specified doesn't exist. I'm confused.

Here is my code:`

<?php

namespace App\Http\Controllers;

//namespace App\Http\Request;

//use Illuminate\Http\Requests;

//use app\Http\Requests\ContactFormRequest;
use App\Message;

use App\Mail\SendMessage;
use Session;

//use App\Requests;


class AboutController extends Controller
{
  public function create()
  {
    return view ('about.contact');
  }
  public function store(App\Requests\SendMessageRequest $request)
  {
$message = $request->message;
Mail::to('myemail')
      ->send(new SendMessage($message, $request->email,$request->name));

THE REQUESTS CLASS

<?php

 namespace App\Http\Requests;

 use Illuminate\Foundation\Http\FormRequest;

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

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

The commented line(//) are what I've tried SendMessageRequest is the name of my Request class.

Maraboc
  • 10,550
  • 3
  • 37
  • 48
Vanessa
  • 43
  • 3
  • 12

1 Answers1

0

Sorry, I can´t comment your post. However can you also send the SendMessageRequest Class? Is that a subclass of the Request in Laravel?

Benni
  • 130
  • 10
  • Yes it's a sub class of Request class. I created it by doing php artisan make:request. This is what it has: I edited the original post to reflect that, pls check, Thanks. – Vanessa Jul 12 '17 at 12:33
  • Do not use such a Request class. Why? It is not necessary. Authorization -> Use the middleware, Validation Rules are static or put it in your ParentController to use in multiple Controllers. I can provide you more information, if you need. – Benni Jul 12 '17 at 12:39
  • If you want to use the subclass: You’ll then need to set it in `public/index.php:$response = $kernel->handle( $request = App\Http\ SendMessageRequest::capture() );` - but that´s for the whole application – Benni Jul 12 '17 at 12:41
  • thought the request class was to get data from the view like so: $request->email. I'm trying to get the email entered in a contact form and that's the reason I'm using Requests not exactly validation – Vanessa Jul 12 '17 at 12:45
  • Use the Laravel Request Class. You can get input with: `$name = $request->input('name');` or if you want to use your class, see my comments above. – Benni Jul 12 '17 at 12:47
  • Okay. So i use that input style and pass Request $request to the controller and reference the namespace but upon running, I get Reflection Exception "Class App\Http\Controllers\Request does not exist" – Vanessa Jul 12 '17 at 12:56
  • You had to import the Request class use Illuminate\Http\Request; – Benni Jul 12 '17 at 13:00
  • I dunno why it still checks for Requests in Controllers namespace cos even after adding illuminate as suggested I still get Class App\Http\Controllers\Request does not exist – Vanessa Jul 12 '17 at 13:09
  • Do you change `public function store(App\Requests\SendMessageRequest $request)` to that `public function store(Request $request)` ? – Benni Jul 12 '17 at 13:10
  • can you please update your code, so it is easier to find the error for me. – Benni Jul 12 '17 at 13:21