php - How to return the view from controller in laravel in this case

931

My question is how should I connect the things to return the view? All of the time got an error like this:

MethodNotAllowedHttpException in RouteCollection.php line 251

Below you can check where I am:

web.php

Route::post('registered', '[email protected]_view')->name('registration.registered');

AuthController.php

public function store_view(Request $request)
{
    $this->validate($request, [
        'name' => 'required',
        'email' => 'required|email',
        'password' => 'required|min:5'
    ]);

    $name = $request->input('name');
    $email = $request->input('email');
    $password = $request->input('password');

    $user = new User([
        'name' => $name,
        'email' => $email,
        'password' => bcrypt($password)
    ]);

    if ($user->save()) {
        $user->signin = [
            'href' => 'api/v1/user/signin',
            'method' => 'POST',
            'params' => 'email, password'
        ];
        $response = [
            'msg' => 'User created',
            'user' => $user
        ];
        return view('registration.registered')->with('response',$response);
    }

    $response = [
        'msg' => 'An error occurred'
    ];

    return view('registration.registered')->with('response',$response);
}

register.blade.php

<div >
  <div >
    <div >
      <div >
        <div >
          <strong> Register to continue!</strong>
        </div>
        <div >
          <form role="form" action="{{-- {{ url('/api/v1/user') }} --}}" method="POST">
          {{ csrf_field() }}
            <fieldset>

              <div >
                <div >
                  <img 
                    src="{{ URL::to('img/key.png') }}" alt="key">
                </div>
              </div>

              <div >
                <div >

                  <div >
                    <div >
                      <span >
                        <i ></i>
                      </span> 
                      <input placeholder="Username" name="name" type="text" autofocus>
                    </div>
                  </div>

                  <div >
                    <div >
                      <span >
                        <i ></i>
                      </span> 
                      <input placeholder="E-mail" name="email" type="text">
                    </div>
                  </div>

                  <div >
                    <div >
                      <span >
                        <i ></i>
                      </span>
                      <input placeholder="Password" name="password" type="password">
                    </div>
                  </div>

                  <div >
                    <input type="submit" value="Register">
                  </div>

                </div>
              </div>

            </fieldset>
          </form>
        </div>
        <div >
          Already have an account? <a href="{{route('sign.login')}}" onClick=""> Sign In Here! </a>
        </div>
      </div>
    </div>
  </div>
</div>
587

Answer

Solution:

In your form use this, the form action attribute must be the name of you route:

<form role="form" action="{{route('registration.registered')}}"

People are also looking for solutions to the problem: PHP 6 sided die counting number of rolls

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.