zxtanzxzx

zxtanzxzx

Member Since 2 Years Ago

Experience Points
7,190
Total
Experience

2,810 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
59
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    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.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 2
7,190 XP
Sep
23
1 month ago
Activity icon

Awarded Best Reply on Input Field Dissappear When Click Livewire Action

after some try and error, i found out that the issue is duplicate id.

Activity icon

Replied to Input Field Dissappear When Click Livewire Action

after some try and error, i found out that the issue is duplicate id.

Sep
22
1 month ago
Activity icon

Started a new Conversation Input Field Dissappear When Click Livewire Action

I am trying to create a dynamic form using livewire that allow user to add more members When i click the "Add Member" button, the event trigger and new member fields was added. However, when the second new member fields added, the existing first field will somehow dissappear.

Look at the screenshot here: https://imgur.com/a/YO9PlwQ

Livewire member.blade

<div>
    {{-- First Member --}}
    <div>
        <div>
            <button class="btn btn-danger btn-sm" wire:click.prevent="add({{$i}})">Add Member</button>
        </div>
        <div>
            <div>
                <label for="memberType">Member Type</label>
                <select name="memberType" id="memberType">
                    <option value="0">TAR UC Student</option>
                    <option value="1">TAR UC Staff</option>
                </select>
            </div>
        </div>
    </div>

    {{-- Second and More Member --}}
    @foreach ($inputs as $key => $value)
    <br>
    <div>
        <div>
            <div>
            <button class="btn btn-danger btn-sm" wire:click.prevent="remove({{$key}})">remove Member {{$key}}</button>
            </div>
        </div>
        <div>
            <label for="memberType">Member Type</label>
            <select name="memberType" id="memberType">
                <option value="0">Student</option>
                <option value="1">Staff</option>
            </select>
        </div>
    </div>
    @endforeach
</div>

Livewire member.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class Member extends Component
{
    public $member_type;

    public $member_list = [
        'member' => [],
        'index' => 0,
    ];

    public $updateMode = false;
    public $inputs = [];
    public $i = 1;

    public function add($i)
    {
        if (count($this->inputs)  < 10) {
            $i = $i + 1;
            $this->i = $i;
            array_push($this->inputs , $i);
        } 
    }

    public function remove($i)
    {
        unset($this->inputs[$i]);
    }

    public function render()
    {
        return view('livewire.member');
    }
}
May
25
5 months ago
Activity icon

Replied to Too Many Redirection

Great! Thanks a lot

May
24
5 months ago
Activity icon

Started a new Conversation Too Many Redirection

I am trying to create a multi auth system. If i try to browse the login page or home page after logged in, the browser shows a 'redirected too many times' error.

handler.php

<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Auth\AuthenticationException;
use Throwable;
use Arr;
use Request;
class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * @param  \Throwable  $exception
     * @return void
     *
     * @throws \Exception
     */
    public function report(Throwable $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Throwable  $exception
     * @return \Symfony\Component\HttpFoundation\Response
     *
     * @throws \Throwable
     */
    public function render($request, Throwable $exception)
    {
        return parent::render($request, $exception);
    }

    /**
     * Convert an authentication exception into a response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Illuminate\Auth\AuthenticationException  $exception
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function unauthenticated($request, AuthenticationException $exception)
    {
        $guard = Arr::get($exception->guards(), 0);
        if ($guard != null) {
            if ((Request::is('user/*')) && $guard = 'user') {
                return redirect(route('user-login-form'));
            }
            else if ((Request::is('admin/*')) && $guard = 'admin') {
                return redirect(route('admin-login-form'));
            }
            else if ((Request::is('moderator/*')) && $guard = 'moderator') {
                return redirect(route('moderator-login-form'));
            }
        }
    }
}

RedirectIfAuthenticated.php

<?php

namespace App\Http\Middleware;

use App\Providers\RouteServiceProvider;
use Closure;
use Route;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if ($guard != null) {
            if ((Route::current()->getName() == 'user-login-form') && Auth::guard()->check('user')) {
                return redirect(route('user-home'));
            }
            if ((Route::current()->getName() == 'admin-login-form') && Auth::guard()->check('admin')) {
                return redirect(route('admin-home'));
            }
            if ((Route::current()->getName() == 'moderator-login-form') && Auth::guard()->check('moderator')) {
                return redirect(route('moderator-home'));
            }
        }
        return $next($request);
    }
}
Activity icon

Replied to Bad Method Called, RedirectResponse::intended()

i am sorry for late reply. You're right. Removed and replace the sendLoginResponse with your answer fixed it. However, the redirectTo function is expecting a string. I have to remove the 'redirect()' elses it will return 'header contain more than single header error'.

May
17
5 months ago
Activity icon

Started a new Conversation Bad Method Called, RedirectResponse::intended()

I was trying to create a multi auth demo project. Everything went smooth untill i got "BadMethodCallException : Call to undefined method Illuminate\Http\RedirectResponse::intended()" This happened after i tried to login.

Login Controller

<?php

namespace App\Http\Controllers\Auth\Moderator;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class ModeratorLoginController extends Controller
{
    use AuthenticatesUsers;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest:moderator')->except('logout');
    }
    
    /**
     * Show login form for user
     */
    public function showLoginForm()
    {
        return view('auth.moderator_login');
    }

    public function login(Request $request)
    {
        $this->validateLogin($request);

        if (method_exists($this, 'hasTooManyLoginAttempts') &&
            $this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        if ($this->attemptLogin($request)) {
            return $this->sendLoginResponse($request);
        }

        $this->incrementLoginAttempts($request);

        return $this->sendFailedLoginResponse($request);
    }

    /**
     * Get the login email of the user
     */
    public function username()
    {
        return 'email';
    }

    /**
     * Log the user out of the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function logout(Request $request)
    {
        $this->guard('moderators')->logout();

        $request->session()->invalidate();

        $request->session()->regenerateToken();

        if ($response = $this->loggedOut($request)) {
            return $response;
        }

        return $request->wantsJson()
            ? new Response('', 204)
            : redirect('/');
    }

    /**
     * Send the response after the user was authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();

        $this->clearLoginAttempts($request);

        if ($response = $this->authenticated($request, $this->guard()->user())) {
            return $response;
        }

        return $request->wantsJson()
                    ? new Response('', 204)
                    : redirect(route('moderator-home'))->intended($this->redirectPath());
    }
}

User Model

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class Moderator extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}