0% found this document useful (0 votes)
7 views8 pages

Laravel Command

This document provides a step-by-step guide to setting up basic authentication in a Laravel project, including creating a new project, configuring the database, running migrations, and optional email configuration for password resets. It also covers testing the authentication system and customizing the registration and login processes. Additionally, it includes instructions for modifying the guest layout to remove or replace the default Laravel logo with a custom logo.

Uploaded by

hamza.hooriakhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Laravel Command

This document provides a step-by-step guide to setting up basic authentication in a Laravel project, including creating a new project, configuring the database, running migrations, and optional email configuration for password resets. It also covers testing the authentication system and customizing the registration and login processes. Additionally, it includes instructions for modifying the guest layout to remove or replace the default Laravel logo with a custom logo.

Uploaded by

hamza.hooriakhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

composer create-project --prefer-dist laravel/laravel project-name

cd authentication-demo

composer require laravel/ui

php artisan ui bootstrap –auth

npm install && npm run dev

php artisan serve

Step 3: Database Configuration

Aapko apne database settings ko configure karna hoga. Laravel .env file mein database settings
hoti hain.

1. .env file open karna: .env file ko open karein aur apne database ke credentials update
karein:

ini
Copy
DB_CONNECTION=mysql
DB_HOST=[Link]
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password

2. Database create karna: Aapko apne database ko manually MySQL ya phpMyAdmin ke


zariye create karna padega. Example: authentication_demo

Step 4: Migrations Run Karna

Laravel mein authentication system ko properly chalane ke liye, kuch tables (like users,
password_resets, etc.) ki migrations run karni hoti hain.

1. Migrations ko run karna: Laravel ne authentication ke liye pre-built migrations diye


hain. Inko run karne ke liye:

bash
Copy
php artisan migrate

Yeh command users, password_resets, aur failed_jobs tables ko database mein


create kar degi.

Step 5: Email Configuration (Optional for Password Reset)


Agar aap password reset ka feature use karna chahte hain, toh email configuration karni hogi.

1. Email settings configure karna (.env): Agar aap mail bhejna chahte hain (e.g., for
password reset), toh aapko .env file mein mail configuration set karni hogi.

Example SMTP settings:

ini
Copy
MAIL_MAILER=smtp
MAIL_HOST=[Link]
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

Agar aap Mailtrap ya Gmail ka use kar rahe hain, toh unke respective credentials daalein.

2. Email verification ka feature: Laravel mein email verification ka bhi feature available
hai, agar aapko users ke email verify karne hain toh:
o Users model mein MustVerifyEmail trait add karna hoga:

php
Copy
use Illuminate\Contracts\Auth\MustVerifyEmail;

class User extends Authenticatable implements MustVerifyEmail


{
// ...
}

o Routes ko modify karna hoga agar aap email verification enable karte hain:

php
Copy
Route::get('/email/verify', function () {
return view('[Link]');
})->middleware(['auth'])->name('[Link]');

Route::get('/email/verify/{id}/{hash}', function () {
// Handle email verification
})->middleware(['auth', 'signed'])->name('[Link]');

Step 6: Test Authentication (Login, Registration)

Ab aapko apne authentication ko test karna hoga.


1. Login/Registration Page: Aap apne browser mein [Link] ya
[Link] open karke registration aur login pages dekh sakte
hain.
2. Registration Test Karna: Jab aap registration form bharte hain aur submit karte hain, ek
naya user database mein insert ho jayega aur aapko login karne ka option milega.
3. Login Test Karna: Jab aap login karte hain, toh aap apne dashboard pe redirect ho
jaenge. By default, Laravel home page ya dashboard route ko secure karta hai.

Step 7: Customization

Agar aapko koi customizations karni hain (jaise validation, custom fields, etc.), toh aap
app/Http/Controllers/Auth mein controllers ko modify kar sakte hain.

1. Registration Controller: [Link] file mein aap registration ke rules


aur custom fields add kar sakte hain.

Example:

php
Copy
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255',
'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'phone' => ['required', 'string', 'min:10'], // Custom field
for phone
]);
}

2. Login Controller: Aap login validation aur authentication ko bhi modify kar sakte hain
agar required ho.

Conclusion:

Ab aapka Laravel project basic authentication (login, registration, password reset) setup ho
chuka hai. Aapko kuch simple steps follow karne padte hain:

 Laravel UI install karna


 Auth scaffolding setup karna
 Database configuration karna
 Migrations run karna
 (Optional) Email configuration
  Directory mein jaana: cd C:\Users\DELL\Documents\laravelpro\new-pro
  php artisan ui bootstrap --auth run karen (agar authentication setup karna
hai)
  npm install && npm run dev run karen (frontend dependencies ko install karne
aur compile karne ke liye)
  php artisan serve se server start karen.

<x-guest-layout>

<!-- Session Status -->

<x-auth-session-status class="mb-4" :status="session('status')" />

<form method="POST" action="{{ route('login') }}">

@csrf

<!-- Email Address -->

<div>

<x-input-label for="email" :value="__('Email')" />

<x-text-input id="email" class="block mt-1 w-full" type="email"


name="email" :value="old('email')" required autofocus autocomplete="username" />

<x-input-error :messages="$errors->get('email')" class="mt-2" />

</div>

<!-- Password -->

<div class="mt-4">

<x-input-label for="password" :value="__('Password')" />

<x-text-input id="password" class="block mt-1 w-full"

type="password"

name="password"

required autocomplete="current-password" />


<x-input-error :messages="$errors->get('password')" class="mt-2" />

</div>

<!-- Remember Me -->

<div class="block mt-4">

<label for="remember_me" class="inline-flex items-center">

<input id="remember_me" type="checkbox" class="rounded border-gray-300 text-indigo-600


shadow-sm focus:ring-indigo-500" name="remember">

<span class="ms-2 text-sm text-gray-600">{{ __('Remember me') }}</span>

</label>

</div>

<div class="flex items-center justify-end mt-4">

@if (Route::has('[Link]'))

<a class="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none


focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" href="{{ route('[Link]') }}">

{{ __('Forgot your password?') }}

</a>

@endif

<x-primary-button class="ms-3">

{{ __('Log in') }}

</x-primary-button>

</div>

</form>

</x-guest-layout>

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Agar tum Laravel Breeze use kar rahe ho aur login/register pages se Laravel ka default logo
hatana chahte ho, toh tumhe [Link] file edit karni hogi.

Step 1: Guest Layout File Open Karo

📌 File Location:
resources/views/layouts/[Link]

Step 2: Logo Code Remove Ya Change Karo

Is file ke andar Laravel ka logo yeh code render karta hai:

<div class="shrink-0 flex items-center">


<a href="/">
<x-application-logo class="w-20 h-20 fill-current text-gray-500" />
</a>
</div>
✅ Option 1: Logo Hatao (Remove Logo)

Agar sirf Laravel ka logo hatana chahte ho, toh yeh code delete ya comment kar do:

{{-- Laravel Logo Remove Karne Ke Liye Yeh Line Comment Ya Delete Kar Do --}}
{{-- <x-application-logo class="w-20 h-20 fill-current text-gray-500" /> --}}

Ab Laravel ka default logo show nahi hoga.

✅ Option 2: Apna Custom Logo Lagao

Agar apna khud ka logo lagana chahte ho, toh Laravel ka logo hata ke apni image ka path do:

<a href="/">
<img src="{{ asset('images/[Link]') }}" alt="My Logo" class="w-20 h-20">
</a>

📌 Note:

 Tumhara logo image file "public/images/[Link]" folder me honi chahiye.


 Agar image "storage/app/public/images/" folder me hai, toh terminal me yeh command
run karo:
 php artisan storage:link
@@@@@@2222@@@@222@@@@@@@

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="csrf-token" content="{{ csrf_token() }}">

<title>{{ config('[Link]', 'Laravel') }}</title>

<!-- Fonts -->

<link rel="preconnect" href="[Link]

<link href="[Link]

family=figtree:400,500,600&display=swap" rel="stylesheet" />

<!-- Scripts -->

@vite(['resources/css/[Link]', 'resources/js/[Link]'])

</head>

<body class="font-sans antialiased">

<div class="min-h-screen bg-gray-100">

<!-- ✅ Yaha pe Logo Add Kiya -->

<div class="flex justify-center py-4">

<a href="/">

<img src="{{ asset('images/[Link]') }}" alt="My Logo"

class="w-20 h-20">

</a>

</div>

@include('[Link]')
<!-- Page Heading -->

@isset($header)

<header class="bg-white shadow">

<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">

{{ $header }}

</div>

</header>

@endisset

<!-- Page Content -->

<main>

{{ $slot }}

</main>

</div>

</body>

</html>

Isse storage folder accessible ho jayega.

Step 3: Save & Refresh Page

File save karke browser refresh karo, Laravel ka logo hat jayega ya tumhara custom logo
dikhne lagega! 🚀

Agar koi aur confusion hai toh batao! 😊

You might also like