Laravel

68

Solutions

81

Contributors

Laravel is a free, open-source PHP web application framework for the development of web applications following the model–view–controller (MVC) architectural pattern. Some of the features of Laravel are a modular packaging system with a dedicated dependency manager, different ways for accessing relational databases, utilities that aid in application deployment and maintenance, and its orientation toward syntactic sugar. Laravel is regarded as one of the most popular PHP frameworks.

Share tech news, updates, or what's on your mind.

Sign up to Post

Routes.php

Route::get('/api/v1/authenticate/user','Authenticate\AuthenticateController@login');
	 
Route::group(['middleware' => 'jwt.auth'], function () {
	 Route::get('/api/v1/authenticate/user', 'Authenticate\AuthenticateController@getAuthUser');
});

Open in new window


authJWT.php

<?php

namespace App\Http\Middleware;

use Closure;
use JWTAuth;
use Exception;

class authJWT
{
    public function handle($request, Closure $next)
    {
        try {
            $user = JWTAuth::toUser($request->input('token'));
        } catch (Exception $e) {
            if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException){				
                return response()->json(['error'=>'Token is Invalid']);
            }else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException){
                return response()->json(['error'=>'Token is Expired']);
            }else{
                return response()->json(['error'=>'Something is wrong']);
            }
        }
        
		return $next($request);
    }
}

Open in new window


AuthenticationController.php

<?php

namespace App\Http\Controllers\Authenticate;

use Illuminate\Support\Facades\DB;
use Illuminate\Pagination\Paginator;
use App\Models\Authenticate;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use JWTAuth;
use JWTAuthException;
use Console;

class AuthenticateController extends Controller
{
	public function login(Request $request){
							
			$credentials = $request->only('email', 'password');
			$token = null; 
			 
			try {
			   if (!$token = JWTAuth::attempt($credentials)) {
					return response()->json(['error' => 'Invalid Login Credentials'], 422);
			   }
			} catch (JWTAuthException $e) {
					return response()->json(['error' => 'Failed To Create Token'], 500);
			}
			
			return response()->json(compact('token'));

	}
	
	public function getAuthUser(Request $request){
        $user = JWTAuth::toUser($request->token);
        return response()->json(['result' => $user]);
    }
}

Open in new window


AuthenticationController.js

	$scope.login = function(){		
		
		var credentials = {
             email: $scope.email,
             password: $scope.password
        }
		
		$http({
			method: 'GET',
			url: '/api/v1/authenticate/user',
			params: credentials
		}).then(function successCallback(response){
			$state.go('Employee');
		}, function errorCallback(response) {
			$scope.loginError = true;
			$scope.loginErrorText = response.data.error;
		});		
		
	}

Open in new window


I implemented all the above but when I submit any email and password it doesn't throw an invalid login credentials. Rather it redirects to the Employee page and that's a problem. Did I miss something.

Your help is kindly appreciated.

Thank You.
0
The Orion Papers
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Hello Experts,

I would like to know if the is a authentication library within Laravel Framwork can support the following requirements? If so, what is it?

any immediate help is highly appreciated.
-regards

> - Application to prevent the re-use of the last 4 passwords.
> - After 5 failed login attempts to the application, further login attempts will remain locked until the affected account is unlocked by an administrator.
> - Password aging set to no more than 90 days, after that they should be reset.
> - Unused accounts should be disabled after one year of inactivity so that they may not be used to access the application.
> - After 5 failed login attempts to the application, further login attempts will be made impossible until the affected account is unlocked by an administrator.
0
We need a website for offering jobs and recruitment just like this one https://www.bayt.com
there are different ways to do that. we can develop our own frame work for it or we can use open source for the backend and maybe tamplates for the front end.
I want you to analyse this project requirements .
Please help me to find the requirements for this project.
0
ErrorException in Macroable.php line 74:
Method appends does not exist. (View: C:\xampp\htdocs\elasticsearch\resources\views\presult.blade.php) (View: C:\xampp\htdocs\elasticsearch\resources\views\presult.blade.php)

foreach($books as $key => $value)

            <article class="one-third">
              <figure><a href="#" title=""><img src="{{ $value['photo_url'] }}" alt="" style="height: 215px!important;" /></a></figure>

              <div class="details">
           
                <h3>{{ $value['name'] }}
                  <span class="stars">{{ $value['class'] }} 
                    <i class="material-icons">&#xE838;</i>
                    <i class="material-icons">&#xE838;</i>
                    <i class="material-icons">&#xE838;</i>
                    <i class="material-icons">&#xE838;</i>
                  </span>
                </h3>
                <span class="address">{{ $value['city_hotel'] }},{{ $value['address'] }}  <a href="hotel?query={{ $value['name'] }}">Show on map</a></span>
                <span class="rating">{{ $value['preferred'] }}</span>
                <span class="price">Max rate  <em>$ {{ $value['maxrate'] }}</em> </span>
                <span class="price">Min rate  <em>$ {{ $value['minrate'] }}</em> </span>
                <div class="description">
                  <p>{{ $value['desc_en'] }}<a href="hotel.html">More info</a></p>
                </div>   
                <a href="{{ $value['hotel_url'] }}" 

Open in new window

0
I am trying to run this command : "php artisan serve " in laravel 5.1 and its giving me a massage "could not open input file artisan"
0
I want to build Laravel based CMS with following requirements:

1. Multi-sites (running on sub-domains, manage own database) each with API access.
2. Admin (manage all sites/database).
3. Same Codebase (can be replicated if needed).
4. Same Database with different data for each site.

Can someone guide me how to develop such system using Laravel 5.4.

I know there are some packages that I can use i.e
Multi Tenant Laravel

This package create separate database/tables for each site, which I think makes problem for me to create single super admin.

Any thoughts?

Thanks.
2

Laravel

68

Solutions

81

Contributors

Laravel is a free, open-source PHP web application framework for the development of web applications following the model–view–controller (MVC) architectural pattern. Some of the features of Laravel are a modular packaging system with a dedicated dependency manager, different ways for accessing relational databases, utilities that aid in application deployment and maintenance, and its orientation toward syntactic sugar. Laravel is regarded as one of the most popular PHP frameworks.

Top Experts In
Laravel
<
Monthly
>