Turn Your Vehicle Into a Smart Earning Asset

While you’re not driving your car or bike, it can still be working for you. MOTOSHARE helps you earn passive income by connecting your vehicle with trusted renters in your city.

πŸš— You set the rental price
πŸ” Secure bookings with verified renters
πŸ“ Track your vehicle with GPS integration
πŸ’° Start earning within 48 hours

Join as a Partner Today

It’s simple, safe, and rewarding. Your vehicle. Your rules. Your earnings.

How to Create a Simple Login Authentication System in LARAVEL?Part-2

How to Create a Simple Login Authentication System in LARAVEL?

Firstly, Visit this Blog Part-1.

Step 15. Now add these classes within MainController file.

use Validator;
use Auth;Code language: PHP (php)

Step 16. Create a function checklogin to receive login form request within the MainController file.

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/successlogin');
     }
     else
     {
      return back()->with('error', 'Wrong Login Details');
     }

    }
Code language: PHP (php)

Step 17. Write down the following code within the login form file for validation error:


   @if (count($errors) > 0)
    <div class="alert alert-danger">
     <ul>
     @foreach($errors->all() as $error)
      <li>{{ $error }}</li>
     @endforeach
     </ul>
    </div>
   @endifCode language: HTML, XML (xml)

Step 18. Write down the following code to display an error message within login form file:

@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>
   @endifCode language: HTML, XML (xml)

Step 19. Now, Create a function checklogin to within the MainController file.

function successlogin()
    {
     return view('successlogin');
    }

    Code language: JavaScript (javascript)

Step 20. Create a successlogin form file within resources/views

Step 21. Create a function logout to within the MainController file.

 function logout()
    {
     Auth::logout();
     return redirect('main');
    }Code language: PHP (php)

Step 22. Go to web.php file and we have to set route of all requests.

Route::get('/main', 'MainController@index');
Route::post('/main/checklogin', 'MainController@checklogin');
Route::get('main/successlogin', 'MainController@successlogin');
Route::get('main/logout', 'MainController@logout');
Code language: PHP (php)

Step 23. Write down the following statement code within the login form.

 @if(isset(Auth::user()->email))
    <script>window.location="/main/successlogin";</script>
   @endifCode language: HTML, XML (xml)

Thanks

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.