Redirect another page after login in laravel 5
In this tutorial I will show you, how to redirect another page after login successfully in laravel 5 version and laravel latest version 5.4. Laravel is the best framework of PHP and very secure for web application.
When you use any framework for you web application then sometimes you may wish to redirect the user to their previous location or another page URL. That’s like when login successful or when register successful or something wrong then user got to another location.
First pass the form value into the controller page and put in the controller page use Illuminate\Http\Request;. It helps to get form input data and now pass input value in the model page. In controller page store form value in a variable and define a model method and put input variable in the method name. You must call the model class in the controller page below the namespace App\Http\Controllers;.
Now input data match with data base and use DB in the model page for connect with database. After login check return in the controller page. In the controller page set if login success then set redirect to another page.
I will give you an example with source code in the below. So follow the example
Example:
Controller Page:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\User; class LoginController extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; public static function signin(Request $signindata){ $username=$signindata->input('username'); $pwd=$signindata->input('password'); $data=with(new User)->SignIn($username,$pwd); $row=count($data); if($row > 0){ return redirect('/'); }else{ echo "Login data dissmatch match"; } } }
Model Page:
<?php namespace App; use DB; class User extends Authenticatable { public function SignIn($username,$pwd){ $sql=DB::table('signup')->where('username',$username)->where('password',$pwd)->get(); return $sql; } }
Find Yoᥙr Perfect Wand Vibrator