auth attempt in laravel get always false

the attempt() method will hash the password that is sent in. Seeing as your DB entry’s password is ‘admin’ in plaintext, that would fail. Save your password with Hash::make($password); and your problem should be solved.

number to month name in php

How to get number to month name in php

Method 1

$monthNum  = 3;
$dateObj   = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F'); // March

Method 2

$monthNum  = 3;
$monthName = date('F', mktime(0, 0, 0, $monthNum, 10)); // March

print query in laravel

$data['result'] = DB::connection($lang)->table('cal_user_activity')->select('module_id', DB::raw('count(*) as total'))->where(['module'=> $module, 'module_id'=> $module_id])->whereRaw("updated_at >=('" . date('Y-m-d H:i:s') . "'-INTERVAL 15 MINUTE) AND updated_at <='" . date('Y-m-d H:i:s') . "'")->groupBy('module_id')->toSql();

cookie in laravel

Create cookie

 Cookie::queue('user-language', 'en' , 1440);

Get Value From cookie

   $language = Cookie::get('user-language');
    $lang =ucfirst(Cookie::get('user-language'));

Delete cookie

    Cookie::forget('user-language');

Check existance of cookie

if(! Cookie::has('user-language'))
    {
        return redirect(url('my-profile'))->withInput()->with('success','Please select language or contact to administrator');
    }

why cookie not access in laravel constructor controller

I’m trying to set the cookie variable in the construct function, but its setting a hashed variable like below when I do Cookie::get('cookie_name'); in the construct.

eyJpdiI6ImRnRWF3TEa82Wm9cL3lRbng0OW1Wc1FBPT0iLCJ2YWx1ZSI6IlI4TkgwZGd6Mn

index name in laravel migration

<?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('question_ta', function (Blueprint $table) {
            $table->id(); 
            $table->bigInteger('user_id')->nullable();           
            $table->bigInteger('subject_id')->nullable();
            $table->bigInteger('unit_id')->nullable();
            $table->bigInteger('topic_id')->nullable();
            $table->bigInteger('tag_id')->nullable();
            $table->string('sub_tag',500)->nullable();
            $table->integer('level')->nullable();
            $table->string('class',10)->nullable();
            $table->string('exam',500)->nullable();
            $table->string('exam_type',200)->nullable();
            $table->string('question_type',20)->nullable()->default('subjective');
            $table->text('question_description')->nullable();
            $table->text('question')->nullable();
            $table->string('image',200)->nullable();
            $table->text('assertion')->nullable();
            $table->text('reason')->nullable();
            $table->text('statement1')->nullable();
            $table->text('statement2')->nullable();
            $table->text('conclusion1')->nullable();
            $table->text('conclusion2')->nullable();
            $table->text('conclusion3')->nullable();
            $table->text('conclusion4')->nullable();
            $table->integer('complexity')->nullable()->default('10');
            $table->string('answer',5)->nullable();
            $table->tinyInteger('multi_correct')->nullable()->default('0');
            $table->text('option1')->nullable();
            $table->text('option2')->nullable();
            $table->text('option3')->nullable();
            $table->text('option4')->nullable();
            $table->text('option5')->nullable();
            $table->string('image1',200)->nullable();
            $table->string('image2',200)->nullable();
            $table->string('image3',200)->nullable();
            $table->string('image4',200)->nullable();
            $table->string('image5',200)->nullable();
            $table->integer('marks')->nullable();
            $table->text('hint')->nullable();
            $table->text('concept')->nullable();
            $table->text('solution')->nullable();
            $table->string('solution_image',200)->nullable();
            $table->string('solution_video',500)->nullable();
            $table->string('start',10)->nullable();
            $table->string('end',10)->nullable();
            $table->text('note')->nullable();
            $table->string('created_by',1000)->nullable();
            $table->string('edited_by',1000)->nullable();
            $table->string('exam_name',200)->nullable();
            $table->string('exam_year',200)->nullable();
            $table->timestamp('last_edited')->nullable();  
            $table->string('question_catId',200)->nullable();
            $table->string('source',200)->nullable();
            $table->string('chapter_no',100)->nullable();
            $table->double('question_no', 8, 2)->nullable();
            $table->string('paper_no',100)->nullable();
            $table->string('mock_test_no',100)->nullable();
            $table->softDeletes();
            $table->timestamps();
            $table->index(['subject_id', 'unit_id','topic_id','level','tag_id','sub_tag','class','exam','exam_type','question_type'],'subject_and_ids');
        
        });
    }

     
    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('question_ta');
    }
};

laravel pagination not working properly with sb admin 2

How to fix laravel 8 UI paginate problem?

just make sure you have this in your AppServiceProvider.

use Illuminate\Pagination\Paginator;

public function boot()
{
     Paginator::useBootstrap();
}
// Directly in your blade file
$posts->links('pagination::bootstrap-4')

auth attempt laravel 8 with status 1

You just take user status and check user status is true or false. You can take status using Auth::User()->status from auth session. Try this.

public function login(Request $request)
    {
        $request->validate([
            'email' => 'required',
            'password' => 'required',
        ]);
        if(Auth::attempt(['email'=>$request->email,'password'=>$request->password])){
            $userStatus = Auth::User()->status;
            if($userStatus=='1') {
                return redirect()->intended(url('dashboard'));
            }else{
                Auth::logout();
                Session::flush();
                return redirect(url('login'))->withInput()->with('success','You are temporary blocked. please contact to admin');
            }
        }
        else {

            return redirect(url('login'))->withInput()->with('success','Incorrect username or password. Please try again.');
        }
        
         
    }

use array with where in laravel

$assignquestion = DB::table('assign_question')->where('user_id',$user_id)->get();
    $assignq = array();
    foreach($assignquestion as $assign)
    {
    $assignq = array_merge($assignq,json_decode($assign->question_ids,true));
    }
    $data = DB::table('question_master')->whereIn('id',$assignq)->paginate(50);