0

I'm attempting to log in to the dashboard using a combination of email and password. However, I'm encountering an error that prevents me from redirecting to the dashboard. Despite checking the data with the dd function, which confirms that all the data is retrieved from the database, the error persists.

controller:

public function getLogin()
    {
        //check if  admin authentificate
        if (Auth::guard('admin')->check()) {
            //response true so redirect to dashboard admin
            return redirect(route('dasboard.admin'));
        } else {
            //if false redirect to page login
            return view('admins.auth.login');
        }
    }

  
 public function postLogin(Request $request): RedirectResponse
    {
        $credentials =  $this->validate($request, [
            'email' => 'required|email',
            'password' => 'required',
        ]);

        if (Auth::guard('admin')->attempt($credentials)) {

            $user = auth()->guard('admin')->user();

            return redirect()->intended(route('dasboard.admin'));
        }
        return back()->withErrors([
            'email' => 'The provided credentials do not match our records.',
        ])->onlyInput('email');
    }

this is Model Admin:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Role;
use Illuminate\Contracts\Auth\Authenticatable;

class Admin extends Model implements Authenticatable
{
    use HasFactory;

    protected $table = 'admins';
    protected $primaryKey = 'id';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'created_at',
        'update_at',

    ];

     public function getAuthPassword()
    {
        return $this->password;
    }

    public function getAuthIdentifierName()
    {
        return $this->name;
    }

    public function getAuthIdentifier()
    {
        return $this->id;
    }
    public function getRememberToken()
    {
        return $this->token;
    }

    public function setRememberToken($value){
        return $this->token = $value;
    }

    public function getRememberTokenName()
    {
        return $this->token;
    }


  

    public function setAuthIdentifier($id)
    {
        $this->id = $id;
    }

    public function role()
    {
        return $this->belongsTo(Role::class);
    }

}

this is Middlware

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Foundation\Auth\User as Authenticatable;

class AdminAuthenticated extends Authenticatable
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        return $next($request);

        if (Auth::guard('admin')->check()) {
        }

        if ($request->ajax() || $request->wantsJson()) {
            return response('Unauthorized.', 401);
        } else {
            return redirect(route('adminLogin'));
        }
    }
}

database:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('admins', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
         /*    $table->foreignId('role_id');
            $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade')->onUpdate('cascade'); */
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('admins');
    }
};
  • 1
    the error message suggest that there is NO column provided when one is expected is a query: "*select * from `admins` where `` = 1 limit 1)*" not sure how this relates to anything provided in the question – Paul Maxwell Apr 30 '23 at 03:11

0 Answers0