sekar_r24
1 month ago
128
1
Laravel

Issue with passing the variable during logging

Posted 1 month ago by sekar_r24

Hi.,

I have the issue in routing the variable during successful login, from login page to another page. i am trying to get the variable from the database for a drop down list and corresponding the text field. on change has been done with JS

my controller code.,

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator;
use Auth;
use App\Rupaco;

class MainController extends Controller
{
    

    
    function index()
    {
     return view('login');
    }

    function checklogin(Request $request)
    {
     $this->validate($request, [
      'email'   => 'required|email',
      'password'  => 'required|alphaNum|min:3'
     ]);

     $user_data = array(
      'email'  => $request->get('email'),
      'password' => $request->get('password')
     );

     if(Auth::attempt($user_data))
     {
      return redirect('main/order');
     }
     else
     {
      return back()->with('error', 'Wrong Login Details');
     }

    }

    function successlogin(Request $request)
    {
        $p=Rupaco::select('rupaco_list')->where('item_numeric',$request->description)->first();
        return response()->json($p);
        return view('order');

    }

    function logout()
    {
     Auth::logout();
     return redirect('main');
    }
/*

  
*/

}

my route code

<?php

use Illuminate\Support\Facades\Route;
use app\Rupaco;


Route::get('/', function () {
    return view('welcome');
});



Route::get('/uploadfile', '[email protected]');
Route::post('/uploadfile', '[email protected]');

Route::get('/main', '[email protected]');
Route::post('/main/checklogin', '[email protected]');
Route::get('main/order', array('as'=>'order', 'uses'=>'[email protected]'));
//Route::get('main/order', '[email protected]');
Route::get('main/logout', '[email protected]');


order.blade.php

<!doctype html>
<html>

<head>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <link href="{{ asset('css/styles.css') }}" rel="stylesheet" type="text/css">
    <meta charset="utf-8">
    <title>Order Form</title>
</head>

<body>

    <h1>Login Page - Front</h1>

    <div class="container">

    @if(isset(Auth::user()->email))
    <div class="alert alert-danger success-block">
     <strong>Welcome {{ Auth::user()->email }}</strong>
     <br />
     <a href="{{ url('/main/logout') }}">Logout</a>
    </div>
   @else
    <script>window.location = "/main";</script>
   @endif

        <div class="form-group">
        



        <div class="row">
            <div class="col-12 col-sm-12 col-md-4 col-lg-4">
                <label>Matting: 1</label>
                <select id="matting_1" name="matt_1" class="form-control">
                    <option value="0" disabled="true" selected="true"> Select One </option>
                    @foreach ($rupaco_lists as $rupaco_list)
                    <option value="{{ $rupaco_list->description}}">{{ $rupaco_list->item_numeric }}</option>
                    @endforeach
                </select>
            </div>

            <div class="col-12 col-sm-12 col-md-4 col-lg-4">
                <label for="inputAddress2">Name</label>
                <input type="text" class="form-control" readonly id="matting_1_name">
            </div>

            
        </div>

</div>



</body>

</html>

login.blade.php


<!DOCTYPE html>
<html>
 <head>
  <title>Simple Login System in Laravel</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style type="text/css">
   .box{
    width:600px;
    margin:0 auto;
    border:1px solid #ccc;
   }
  </style>
 </head>
 <body>
  <br />
  <div class="container box">
   <h3 align="center">Login System </h3><br />

   @if(isset(Auth::user()->email))
    <script>window.location="/main/order";</script>
   @endif

   @if ($message = Session::get('error'))
   <div class="alert alert-danger alert-block">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>{{ $message }}</strong>
   </div>
   @endif

   @if (count($errors) > 0)
    <div class="alert alert-danger">
     <ul>
     @foreach($errors->all() as $error)
      <li>{{ $error }}</li>
     @endforeach
     </ul>
    </div>
   @endif

   <form method="post" action="{{ url('/main/checklogin') }}">
    {{ csrf_field() }}
    <div class="form-group">
     <label>Enter Email</label>
     <input type="email" name="email" class="form-control" />
    </div>
    <div class="form-group">
     <label>Enter Password</label>
     <input type="password" name="password" class="form-control" />
    </div>
    <div class="form-group">
     <input type="submit" name="login" class="btn btn-primary" value="Login" />
    </div>
   </form>
  </div>
 </body>
</html>

Please sign in or create an account to participate in this conversation.