Member Since 5 Years Ago
4,380 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
Started a new Conversation Usase Of Request::path()
I am trying to use below code in my blade file but it is not working.
@if (Request::path() == 'student-detail/$id')
// some code
@endif
Replied to Dynamic Request Path
Thanks @michaloravec . But I am using Request::path() == 'integration-detail'
in my blade file. How can I use $id
here ?
Started a new Conversation Dynamic Request Path
I am using Request::path()
. It's value will be integration-detail
.
How can I make it dynamic ?
Like integration-detail/2
, integration-detail/9
, integration-detail/5
etc.
Started a new Conversation HTML Tag Are Not Matching
I have below HTML code in blade file.
<div class="col-md-6">
<div class="reg-left">
<h3>Account Login Details</h3>
<form method="POST" id="reg_form" action="" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="email">Email Address*</label>
<input value="{{ old('reg_email') }}" type="email" name="reg_email"
class="form-control @error('reg_email') is-invalid @enderror" placeholder="Email"
id="login_email" required />
</div>
@error('reg_email')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div class="form-group">
<label for="password">Password*</label>
<input type="password" name="password"
class="form-control @error('password') is-invalid @enderror" placeholder="Password"
required />
</div>
@error('password')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div class="form-group">
<label for="password_confirmation">Confirm Password*</label>
<input type="password" name="password_confirmation"
class="form-control @error('password_confirmation') is-invalid @enderror"
placeholder="Confirm Password" required />
</div>
@error('password_confirmation')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<!-- reg-left ./form -->
</div>
<!-- ./reg-left -->
</div>
But I am getting RED div tag like below
Replied to Google ReCaptcha Is Absent In $request Variable
Thanks @michaloravec . I tried with packages. But packages are not good. Thanks.
Replied to Google ReCaptcha Validation
Thanks @a4ashraf . You can check this question https://laracasts.com/discuss/channels/laravel/google-recaptcha-is-absent-in-request-variable
Started a new Conversation Google ReCaptcha Is Absent In $request Variable
I am working on a Google reCaptcha Registration
page using Laravel 8. I am not using any package.
I added below code in header.
<script src='https://www.google.com/recaptcha/api.js' async defer></script>
My blade file code is like below
<form method="POST" action="{{ url('/register') }}" enctype="multipart/form-data">
@csrf
<div class="form-group mt-5">
<div class="g-recaptcha" data-sitekey="sitekeytext"></div>
</div>
@error('g-recaptcha-response')
<div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
@enderror
<button type="submit" class="btn mt-3 mb-5">Submit</button>
</form>
I checked reCaptcha check box in Registration
page and submitted the form
I am debugging using below code in Controller.
public function store(Request $request)
{
dd($request); // `g-recaptcha-response` is absent here
}
Why g-recaptcha-response
is absent here ?
Replied to Google ReCaptcha Validation
Thanks @a4ashraf . How same code is working in Login
page. ?
I added below code in header.
<script src='https://www.google.com/recaptcha/api.js' async defer></script>
I added below code in register.blade.php
file.
<div class="form-group mt-5">
<div class="g-recaptcha" data-sitekey="sitekeytext"> </div>
</div>
@error('g-recaptcha-response')
<div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
@enderror
I added below code in RegisteredUserController.php
$request->validate([
'g-recaptcha-response' => 'required',
],
[
'g-recaptcha-response.required' => 'Captcha is Required',
]);
Same code is working in Login
page but it is not working in Registration
page.
Replied to Google ReCaptcha Validation
Thanks @a4ashraf . I am not using any plugin. I checked my JS file. There is no error. Same code is working in Login page but not working in Registration page. Thanks.
Started a new Conversation Google ReCaptcha Validation
I am am working with Google reCaptcha in a Registration
page using Laravel 8. My View (blade) page code is like below.
<div class="form-group mt-5">
<div class="g-recaptcha" data-sitekey="sitekeytext"></div>
</div>
@error('g-recaptcha-response')
<div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
@enderror
My Controller code is like below,
$request->validate([
'g-recaptcha-response' => 'required',
],
[
'g-recaptcha-response.required' => 'Captcha is Required',
]);
After submitting Form
I am getting Captcha is Required
validation message.
Same code is working perfectly on Login
page.
Replied to Return Saved User Object After Sign Up
Thanks @tykus . I would like to fetch User Object from $user_saved
. Is it possible ? How can I get a User Object ?
Started a new Conversation Return Saved User Object After Sign Up
I am saving User
in Database like below
$user = User::where('email',$request->email)->first();
$ver_code = rand(1,9).rand(1,9).rand(1,9).rand(1,9);
$user->ver_code = $ver_code;
$user->account_status = 0;
$user_saved = $user->save();
I would like to return saved User Object. How can I do that ?
Started a new Conversation CURL Error 28:
My code is like below.
$response = Http::post('http://sometext/login', [
'email' => $request->email,
'password' => $request->password,
]);
I am getting below error.
cURL error 28: Failed to connect to xx.xxx.xxx.184 port 80: Connection timed out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://sometext/login
Started a new Conversation Google ReCaptcha With Laravel
I am trying to install Google reCaptcha v2 with Laravel 8 without any packages. I am trying to follow this tutorial. I tried with this tutorial also.
But captcha is not showing in Blade file.
Could anyone please help me to implement Google reCaptcha v2 in Laravel 8 without using any packages with some sample code or tutorial ?
Replied to Using WithErrors([])
@jlrdw Thanks for your reply. I am not using passport or Sanctum. I am using below code for login
$response = Http::post('http://sometext/login', [
'email' => $request->email,
'password' => $request->password,
]);
I need to pass login failed message to blade file.
Replied to Using WithErrors([])
Thanks @jlrdw . I am using Laravel 8. I am using Third Party API for User Authentication.
Started a new Conversation Using WithErrors([])
I am trying to use withErrors([])
like below.
return Redirect::back()->withErrors(
[
'login' => 'Login is not successful.'
]
);
I am getting output like below
array:1 [â–¼
0 => "Login is not successful."
]
Is it possible to get a key
in array while using withErrors([])
?
Started a new Conversation Display Error Message In Login Blade File
I have below code in my login controller.
return redirect('/login')->withErrors('Login is not successful.');
I am displaying all error messages using below code in login.blade.php
file.
@if ($errors->any())
@foreach ($errors->all() as $error)
<div class="alert alert-danger" role="alert">
{{ $error }}
</div>
@endforeach
@endif
If I use above code all the errors are displaying. I would like to display only error of return redirect('/login')->withErrors('Login is not successful.');
this code.
How can I do that ?
Started a new Conversation Controller Does Not Exist.
I have below code in my web.php
file.
Route::group(['middleware' => ['auth:admin']], function () {
Route::prefix('admin')->group(function () {
Route::get('/subscription', 'Admin\[email protected]');
});
});
My controller is like below
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Subscription;
class SubscriptionController extends Controller
{
public function subscriptions()
{
$subscriptions = Subscription::with('course','user')->paginate(20);
dd($subscriptions);
}
}
But I am getting below error
Illuminate\Contracts\Container\BindingResolutionException
Target class [App\Http\Controllers\Admin\SubscriptionController] does not exist.
Started a new Conversation Google ReCAPTCHA V3 In Laravel 8
I am trying to integrate Google reCAPTCHA v3 in Laravel 8. I am trying to follow this tutorial.
I ran this command php artisan vendor:publish --provider="Lunaweb\RecaptchaV3\Providers\RecaptchaV3ServiceProvider"
I added below code in my blade file.
{!! RecaptchaV3::initJs() !!}
{!! RecaptchaV3::field('register') !!}
But I can't see Google reCAPTCHA.
Started a new Conversation Send Mail From Laravel
I am trying to send mail from Laravel. My .env
file code is like below.
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=12345678
MAIL_ENCRYPTION=ssl
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
When I received mail I am getting sender address [email protected]
. How can I avoid it ? I need [email protected]
as sender address.
Thanks @neeraj1005 . What is app password ?
Started a new Conversation OTP Using REST API
I never implemented OTP. I am going to implement OTP using Laravel REST API. Could any one guide me which steps should I need to implement OTP using Laravel REST API ?
Replied to Session::flush();
Thanks @guybrush_threepwood . I would like to be sure it is working as expected
Started a new Conversation Session::flush();
How to know Session::flush();
is worked ? Should I use below code ?
$result = Session::flush();
if ($result) {
//do something
}
Started a new Conversation Set & Get Session Variable Value
I am setting session variable in function of a controller like below.
use Illuminate\Support\Facades\Session;
class UserController extends Controller
{
public function store(Request $request)
{
session(['user_name' => $user_name]);
}
}
I am trying to access that session variable in another function of another controller.
use Illuminate\Support\Facades\Session;
class DashboardController extends Controller
{
public function __construct()
{
dd(session('user_name')); // I am not getting value here
}
}
I am not getting value from Session Variable.
Started a new Conversation Route Not Found
I am using Laravel Breeze . My web.php
file is like below
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth'])->name('dashboard');
require __DIR__.'/auth.php';
My auth.php
file is like below.
<?php
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\Auth\ConfirmablePasswordController;
use App\Http\Controllers\Auth\EmailVerificationNotificationController;
use App\Http\Controllers\Auth\EmailVerificationPromptController;
use App\Http\Controllers\Auth\NewPasswordController;
use App\Http\Controllers\Auth\PasswordResetLinkController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Auth\VerifyEmailController;
use Illuminate\Support\Facades\Route;
Route::get('/register', [RegisteredUserController::class, 'create'])
->middleware('guest')
->name('register');
Route::post('/register', [RegisteredUserController::class, 'store'])
->middleware('guest');
Route::get('/login', [AuthenticatedSessionController::class, 'create'])
->middleware('guest')
->name('login');
Route::post('/login', [AuthenticatedSessionController::class, 'store'])
->middleware('guest');
Route::get('/forgot-password', [PasswordResetLinkController::class, 'create'])
->middleware('guest')
->name('password.request');
Route::post('/forgot-password', [PasswordResetLinkController::class, 'store'])
->middleware('guest')
->name('password.email');
Route::get('/reset-password/{token}', [NewPasswordController::class, 'create'])
->middleware('guest')
->name('password.reset');
Route::post('/reset-password', [NewPasswordController::class, 'store'])
->middleware('guest')
->name('password.update');
Route::get('/verify-email', [EmailVerificationPromptController::class, '__invoke'])
->middleware('auth')
->name('verification.notice');
Route::get('/verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke'])
->middleware(['auth', 'signed', 'throttle:6,1'])
->name('verification.verify');
Route::post('/email/verification-notification', [EmailVerificationNotificationController::class, 'store'])
->middleware(['auth', 'throttle:6,1'])
->name('verification.send');
Route::get('/confirm-password', [ConfirmablePasswordController::class, 'show'])
->middleware('auth')
->name('password.confirm');
Route::post('/confirm-password', [ConfirmablePasswordController::class, 'store'])
->middleware('auth');
Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])
->middleware('auth')
->name('logout');
My HTML code in blade file is like below
<a href="{{ route('register') }}">
<button type="button">Register</button>
</a>
I am getting error like below
Replied to Laravel Layout
Thanks @siangboon . My menu.blade.php
is like below.
@extends('dashboard')
@section('menu')
// more HTML code
@endsection
Should I use dashboard.blade.php
like below ?
@extends('layouts.master')
@section('content')
@include('layouts.menu') // Should I do this ?
// more HTML code
@endsection
Should I do this ?
Started a new Conversation Laravel Layout
My master.blade.php
file is like below
<body>
@include('layouts.header')
@yield('content')
@include('layouts.footer')
@include('layouts.footer-script')
</body>
My dashboard.blade.php
file is like below
@extends('layouts.master')
// I would like to add Menu here
@section('content')
//more code here
@endsection
How can I add Menu
in dashboard.blade.php
?
Started a new Conversation Action [email protected] Not Defined
My DashboardController
is like below.
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Http;
class DashboardController extends Controller
{
public function index()
{
echo 'hello';
}
}
My web.php
file is like below
<?php
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;
Route::get('/dashboard', [DashboardController::class, 'index']);
I have code in another file is like below
if ($session_token) {
return redirect()->action('[email protected]');
} else {
return redirect('/login')->withErrors('Login is not successful.');
}
I am getting error like below
Replied to Login Redirect Is Not Working.
Thanks @npispas . Yes, I want to authenticate user from a 3rd party service.
Replied to Login Redirect Is Not Working.
Thanks @snapey . I am consuming Bearer Token. I store it in session. I will use it for Authentication.
Replied to Login Redirect Is Not Working.
Thanks @npispas . Actually I would like to fetch token and store it in session for authentication.
Replied to Login Redirect Is Not Working.
Thanks @npispas . Yes, I am reaching the if
statement.
[2021-03-03 02:44:27] local.DEBUG: false
I am getting this if I use your code Log::debug(var_export(Auth::check(), true));
Replied to Login Redirect Is Not Working.
Thanks @npispas . What will be the issue if I place dashboard
route under web routes. I am working in WebSite. How to know dashboard
is protected with the auth
middleware ? My route is like below.
Route::get('/dashboard', function () {
return view('dashboard');
});
Replied to Login Redirect Is Not Working.
Thanks @filip133 . Actually dd($session_token) is a token. Here is the output eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI1IiwianRpIjoiOTU3YzJkNGZlZWFjOThlODQxYTYxZmFlOGJiZjJlMTc2MGRjOTcwOWY5MWI1ZjgwMWZjMTQ2Y2NkZDYwZTBmOWQ0ZTM3YTJkOGE5ZDkzZmYiLCJpYXQiOjE2MTQ2OTM5NjgsIm5iZiI6MTYxNDY5Mzk2OCwiZXhwIjoxNjQ2MjI5OTY4LCJzdWIiOiIyMiIsInNjb3BlcyI6W119.NuUpu5OBMvtJbzA1dUPms9a5FXd2Pxt7RIr99drV06x6YfNr1gV5ySMqp7nSMjnBZv5UbZ_M14uh6VGVhX6Wpz_os7370QPJSsVxu3CACmf43NHpDm7OM1NrV34uEhxit86HUInrbqKG3P70gOqD0jXT_m5L5VUoSrFaXl6AeDzk3Fx8nw0A6KvsfXuIqTyqr2_a0af9UlZ871Z5aqT7DmyEkgedojAS6EfAKPEBiWwsx1c2lruqOXw7HK-my_MLQbic8fjq9IHR9VtG3DBQTB1nTGscM9jpFrONnfJD7X880ssuMFKgmuxGEVgMomUmhi5ZXF15wSdizKMy-IYWeGlmtnBI-MjWRbMtsySjo3F-EyWAESNiwwK7IlCkfFgjAr7BGUGLa1Gy0gXZ3tObsYM95dTbbjIkUHOsIH_8bzU07VvcKBQtHm1NyV0RevAmYtO08aaeMaYXkLSgvG4IsoOtfcm1hdSQPI2D9WnD4eoJY9-kIl1zNmZa9pcL3j3ncUaekGciq9Wrcx9tzKr27hktca4uEP29MxCD4YVAE1LR0lVZmruF6DY7HnrfEoF0VQuqeNvSggB3wiIxGhpzSLlQ5_NUkdbKxPjCDzZHpZF1mt_AntUHSidKCWlFv3EGzGqMyejmRtPLo-wOWFCAl9NbDlMf7icjfh3s5jRyubM
Is it possible to do User Authentication in this Token Based way?
Replied to Login Redirect Is Not Working.
Thanks @npispas . Your solution is not working. I am fetching Token from API EndPoint to store in Session. I would like to use this Token for User Authentication. Auth::check()
will it work in this case ?
Replied to Login Redirect Is Not Working.
Thanks @npispas . I am using this code return redirect()->route('dashboard')->name('dashboard');
. I am this getting error
BadMethodCallException
Call to undefined method Illuminate\Http\RedirectResponse::name()
Replied to Login Redirect Is Not Working.
Thanks @npispas . I am not using route::cache
. I am not getting any error. But the application is redirecting to /login
again.
Started a new Conversation Login Redirect Is Not Working.
I am trying to login though API . My Code is like below.
/**
* Handle an incoming authentication request.
*
* @param \App\Http\Requests\Auth\LoginRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(LoginRequest $request)
{
$response = Http::post('http://moretext/login', [
'email' => $request->email,
'password' => $request->password,
]);
$session_token = str_replace("Bearer ", "", $response->json()['access_token']); // I am getting Token here
if ($session_token) {
Session::put('SesTok', $session_token);
return redirect('/dashboard'); //This redirect is not working.
} else {
return redirect('/login')->withErrors('Login is not successful.');
}
}
I have below code in route.php
file.
Route::get('/dashboard', function () {
return view('dashboard');
});
Replied to Login Through API
Thanks @silencebringer . I tried your solution Auth::check()
. But it is not working. I sent Bearer Token
with API request but it is not working.