Basic Authentication - RESTful API with Laravel - 08

preview_player
Показать описание
Create Basic Authentication API in Laravel and start developing your own APIs.

Remember!
Anybody can learn programming no matter who you are. You just need some time to study.

The most starred PHP framework, Laravel. My goal with this Laravel tutorial to create a guide for those learning the framework. This guide will take you from the very beginning of an idea into a real deployable application.

Laravel api Tutorial
Laravel rest api Tutorial
Laravel api Tutorial for Beginners Step by Step

Laravel Tutorial Series Playlist:

Laravel api Tutorial for Beginners Step by Step Playlist

Laravel Tutorial for Beginners Step by Step Playlist

#LaravelTutorial #LaravelHindi #LaravelTutorialSeries #AtifNaseem #Laravel
Рекомендации по теме
Комментарии
Автор

For those getting 401 Unauthorized blade template instead of json response, use the following code:

use Closure;

use Exception;
use
use
... ... ...
public function handle($request, Closure $next)
{
try {
Auth::onceBasic();
} catch (UnauthorizedHttpException $e) {
return response()->json(
["message" => 'Unauthenticated'],
401
);
} catch (Exception $e) {
return response()->json(
["message" => 'Authentication failed'],
500
);
}
return $next($request);
}

mutasimbillahbinahmad
Автор

great tutor, hope u always update! keep it up

gardaanggara
Автор

At laravel 6.x Auth::onceBasic() throwing standard laravel's 401 page without message 'Auth failed'

MstwaneD
Автор

Hello sir, i got that Auth::onceBasic() is working to check if user isn't logged in but may you please allaborate that, what Auth::onceBasic() this actually doing?

khushalmore
Автор

Hello Atif

I have checked the implementation of " onceBasic " method
it is fetching data from USERS table from email and password column

but not authentication is not successful even when passing the
same email and password as given in table...

can you please suggest what needs to be done

Thanks
- Bhumit

bhumittrivedi
Автор

Invalid login credentials returning response in html formate not JSON as you have shown in your tutorial. Please elaborate that how can get response in json formate rather than HTML.

RockStar-tefy
Автор

Excelente tutorial.. but in Laravel 8 i received error Error: Call to undefined method

helderam
Автор

I want to set separate data(username, password) for api calling. How to do in laravel??
I don`t want to keep a user login to access my api... How to do this? please ...

NazrulIslam-izsw
Автор

Error: Class not found in file on line 19

hurrainfatima
Автор

It's not showing error message. I am using Laravel 6

iammuttaqi
Автор

Doesn't work for custom error messages on Laravel 5.8/6.0

AsfiTanoli
Автор

I use if(Auth::onceBasic() ). But Wheather I login again and agin . it always show 401

陳建至-rx
Автор

simple solution to solve html unauthorized problem is,
go to Handler.php file and add this line in render function

if ($request->expectsJson()) {
return response()->json(["message" => "Auth Failed"], 401);
// or you can replace the line above with this just comment the first line then remove the comment from second line
// return response()->json(["message" =>$exception->getMessage()], 401);


}
return parent::render($request, $exception);

in Postman add header
Accept:application/json

MotasemZindaqy
Автор

make video on codeigniter 4 with basic authentication and api key

saurabhmishra
Автор

What if I want to keep the user logged in?

osiris
Автор

Where username and password is maintained?

pranavpandya