php - Laravel 5 keep redirecting me to `/auth/login` when go to an route post? -


i'm new laravel 5. have route post /subscribe.

//subcribe route::post('/subscribe','subscribecontroller@postsubscribe'); 

when goto it, laravel application auto redirecting me : /auth/login

i notice, in

i have : /app/http/routes.php

route::controllers([  'auth' => 'auth\authcontroller',  'password' => 'auth\passwordcontroller',  ]); 

auth controller

<?php namespace app\http\controllers\auth;  use app\http\controllers\controller; use illuminate\contracts\auth\guard; use illuminate\contracts\auth\registrar; use illuminate\foundation\auth\authenticatesandregistersusers;  class authcontroller extends controller {      /*     |--------------------------------------------------------------------------     | registration & login controller     |--------------------------------------------------------------------------     |     | controller handles registration of new users,     | authentication of existing users. default, controller uses     | simple trait add these behaviors. why don't explore it?     |     */      use authenticatesandregistersusers;      /**      * create new authentication controller instance.      *      * @param  \illuminate\contracts\auth\guard  $auth      * @param  \illuminate\contracts\auth\registrar  $registrar      * @return void      */     public function __construct(guard $auth, registrar $registrar)     {         $this->auth = $auth;         $this->registrar = $registrar;          $this->middleware('guest', ['except' => 'getlogout']);     }  } 

passwordcontroller

<?php namespace app\http\controllers\auth;  use app\http\controllers\controller; use illuminate\contracts\auth\guard; use illuminate\contracts\auth\passwordbroker; use illuminate\foundation\auth\resetspasswords;  class passwordcontroller extends controller {      /*     |--------------------------------------------------------------------------     | password reset controller     |--------------------------------------------------------------------------     |     | controller responsible handling password reset requests     | , uses simple trait include behavior. you're free     | explore trait , override methods wish tweak.     |     */      use resetspasswords;      /**      * create new password controller instance.      *      * @param  \illuminate\contracts\auth\guard  $auth      * @param  \illuminate\contracts\auth\passwordbroker  $passwords      * @return void      */     public function __construct(guard $auth, passwordbroker $passwords)     {         $this->auth = $auth;         $this->passwords = $passwords;          $this->middleware('guest');     }  } 

request @sw

subscribecontroller

<?php  namespace app\http\controllers; use app\subscribe; use input, validator, auth, redirect, request, session, mail, view;  class subscribecontroller extends controller {       public function index()     {          $subscribes = subscribe::all();          return view::make('subscribes.index')         ->with('subscribes',$subscribes);      }      //------------------------------------------------------------------------------------------------- [ create]       public function create()     {          return view::make('subscribes.create');     }      //------------------------------------------------------------------------------------------------- [ store ]       public function store()     {         $validator = subscribe::validator(input::all());          if ($validator->fails()) {               return redirect::to('subscribe/create')             ->witherrors($validator)->withinput();          } else {               $subscribe               = new subscribe;             $subscribe->email  = input::get('email');             $subscribe->save();              return redirect::to('/subscribe')             ->with('success','the web directory created succesfully!');          }     }      //------------------------------------------------------------------------------------------------- [ show ]       public function show($id)     {          $subscribe = subscribe::findorfail($id);         return view::make('subscribes.show')         ->with('subscribe', $subscribe);     }      //------------------------------------------------------------------------------------------------- [ edit ]       public function edit($id)     {          $subscribe = subscribe::findorfail($id);          return view::make('subscribes.edit')         ->with('subscribe', $subscribe );     }      //------------------------------------------------------------------------------------------------- [ update ]       public function update($id)     {         $validation = subscribe::validator(input::all());          if ($validation->fails()) {              return redirect::to('subscribe/'. $id . '/edit')->witherrors($validation);          } else {               $subscribe               = subscribe::findorfail($id);             $subscribe->email  = input::get('email');             $subscribe->save();              return redirect::to('subscribe')             ->with('success','the web directory updated succesfully!');         }     }     //------------------------------------------------------------------------------------------------- [ destroy ]      public function destroy($id){          $subscribe = subscribe::find($id);          $subscribe->delete();          return redirect::to('subscribe')         ->with('success','the web directory deleted succesfully!');      }      public function postsubscribe() {          $subscribe_email = input::only('subscribe_email');          // validation         $validator = validator::make( $subscribe_email ,              array(                  'subscribe_email'  => 'email|unique:subscribes,email',                 )             );          if ($validator->fails()) {              return redirect::to('/#footer')             ->with('subscribe_error', $subscribe_email['subscribe_email']. ' aveniros subscriber.')             ->witherrors($validator)->withinput();          }else{              $subscribe        = new subscribe;             $subscribe->email = input::get('subscribe_email');             $subscribe->save();              return redirect::to('/thank-you');          }      }      public function postsubscribeajax() {          $data = request::all();          //dd($data); stuck here          // validation         $validator = validator::make( $data,              array(                 'subscribe_email' => 'email|unique:subscribes,email',                 )             );           if ($validator->fails()) {              return redirect::to('/#footer')             ->with('subscribe_error','this email subscribed us.')             ->witherrors($validator)->withinput();          }else{              $subscribe = new subscribe;             $subscribe->email = input::get('subscribe_email');             $subscribe->save();             return redirect::to('/thank-you');          }      }        public function thankyou() {         return view('subscribes.thankyou');     }    } 

why ? , how fix ? normal behavior ?

you need have method each of routes, telling laravel how treat each route. example in route file, there should route::get('index@subscribecontroller); line. staurt wagner has mentioned, if navigate path, sending request server.

if using laravel 5, controllers should in \app\http\controllers path. index method in thesubscribecontroller can be:

public function index(){     return "hello world!"; } 

for thorough tutorial, refer this wonderful series on laracast.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -