Laravel CSV import large file AJAX
Learn how to import large CSV files into a users table in Laravel using AJAX with a progress bar. This guide includes duplicate checking, chunk processing, and commented code.
यदि आप अपनी बात दुनिया तक पहुंचाना चाहते हैं, तो एक ब्लॉग बनाना एक शानदार तरीका है। लारवेल (Laravel) के साथ आप एक प्रोफेशनल ब्लॉग बना सकते हैं, जिसमें पोस्ट्स, कमेंट्स, और एडमिन डैशबोर्ड जैसे फीचर्स शामिल हों। इस लारवेल ब्लॉग ट्यूटोरियल हिंदी में (Laravel Blog Tutorial in Hindi) में हम आपको स्टेप-बाय-स्टेप बताएंगे कि लारवेल का उपयोग करके एक ब्लॉग वेबसाइट कैसे बनाई जाती है, जिसमें पोस्ट मैनेजमेंट औ
Table of contents [Show]
यदि आप अपनी बात दुनिया तक पहुंचाना चाहते हैं, तो एक ब्लॉग बनाना एक शानदार तरीका है। लारवेल (Laravel) के साथ आप एक प्रोफेशनल ब्लॉग बना सकते हैं, जिसमें पोस्ट्स, कमेंट्स, और एडमिन डैशबोर्ड जैसे फीचर्स शामिल हों। इस लारवेल ब्लॉग ट्यूटोरियल हिंदी में (Laravel Blog Tutorial in Hindi) में हम आपको स्टेप-बाय-स्टेप बताएंगे कि लारवेल का उपयोग करके एक ब्लॉग वेबसाइट कैसे बनाई जाती है, जिसमें पोस्ट मैनेजमेंट और कमेंट सिस्टम होगा। यह ट्यूटोरियल शुरुआती डेवलपर्स के लिए भी बहुत आसान है। तैयार हैं? चलिए शुरू करते हैं! 🚀
लारवेल से ब्लॉग बनाने की लोकप्रियता क्यों बढ़ रही है? आइए इसके कुछ प्रमुख फायदों पर नजर डालें:
जानकारी: 2025 में 60% ब्लॉगर्स PHP-बेस्ड फ्रेमवर्क्स जैसे लारवेल का उपयोग करते हैं!
लारवेल के साथ आप विभिन्न प्रकार के ब्लॉग प्रोजेक्ट्स बना सकते हैं, जैसे:
सबसे पहले, एक नया लारवेल प्रोजेक्ट बनाएं। इसके लिए आपको निम्नलिखित चीजें चाहिए:
सेटअप कैसे करें?
composer create-project laravel/laravel blog-app
इससे “blog-app” नाम का फोल्डर बनेगा।
cd blog-app
php artisan serve
ब्राउज़र में http://localhost:8000
खोलें, आपको लारवेल का वेलकम पेज दिखेगा।
पोस्ट्स और कमेंट्स को स्टोर करने के लिए डेटाबेस की आवश्यकता होगी।
.env
फाइल में डेटाबेस डिटेल्स अपडेट करें:DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog_db
DB_USERNAME=your_username
DB_PASSWORD=your_password
blog_db
नाम का डेटाबेस बनाएं।php artisan make:model Post -m
php artisan make:model Comment -m
database/migrations/
में पोस्ट माइग्रेशन फाइल में निम्नलिखित कोड डालें:Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('content');
$table->string('image')->nullable();
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
database/migrations/
में कमेंट माइग्रेशन फाइल में निम्नलिखित कोड डालें:Schema::create('comments', function (Blueprint $table) {
$table->id();
$table->text('content');
$table->unsignedBigInteger('post_id');
$table->unsignedBigInteger('user_id');
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
php artisan migrate
app/Models/Post.php
में मॉडल को अपडेट करें:namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $fillable = ['title', 'content', 'image', 'user_id'];
public function user()
{
return $this->belongsTo(User::class);
}
public function comments()
{
*expunged*return $this->hasMany(Comment::class);
}
}
app/Models/Comment.php
में मॉडल को अपडेट करें:namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
protected $fillable = ['content', 'post_id', 'user_id'];
public function post()
{
return $this->belongsTo(Post::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}
यूजर्स के लिए लॉगिन, रजिस्ट्रेशन, और एडमिन डैशबोर्ड सेट करें।
composer require laravel/breeze --dev
php artisan breeze:install
npm install
npm run dev
php artisan migrate
यह लॉगिन, रजिस्ट्रेशन, और डैशबोर्ड सेटअप करेगा।
पोस्ट्स को क्रिएट, लिस्ट, और डिलीट करने के लिए:
php artisan make:controller PostController --resource
app/Http/Controllers/PostController.php
में निम्नलिखित कोड डालें:namespace App\Http\Controllers;
use App\Models\Post;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class PostController extends Controller
{
public function index()
{
$posts = Post::with('user')->latest()->get();
return view('posts.index', compact('posts'));
}
public function create()
{
return view('posts.create');
}
public function store(Request $request)
{
$request->validate([
'title' => 'required|max:255',
'content' => 'required',
'image' => 'nullable|image|max:2048',
]);
$data = $request->all();
$data['user_id'] = Auth::id();
if ($request->hasFile('image')) {
$data['image'] = $request->file('image')->store('images', 'public');
}
Post::create($data);
return redirect()->route('posts.index')->with('success', 'पोस्ट बन गई!');
}
public function show(Post $post)
{
$post->load('comments.user');
return view('posts.show', compact('post'));
}
}
routes/web.php
में रूट्स जोड़ें:use App\Http\Controllers\PostController;
Route::resource('posts', PostController::class)->middleware('auth');
resources/views/posts/index.blade.php
बनाएं और निम्नलिखित कोड डालें:@extends('layouts.app')
@section('content')
ब्लॉग पोस्ट्स (Blog Posts)
@if(session('success'))
{{ session('success') }}
@endif
<a class="btn btn-primary mb-3" href="{{ route('posts.create') }}">नई पोस्ट बनाएं (Create New Post)</a>
@foreach($posts as $post)
@if($post->image)
@endif
<a href="{{ route('posts.show', $post) }}">{{ $post->title }}</a>
{{ Str::limit($post->content, 200) }}
लेखक (Author): {{ $post->user->name }}
@endforeach
@endsection
resources/views/posts/create.blade.php
बनाएं और निम्नलिखित कोड डालें:@extends('layouts.app')
@section('content')
नई पोस्ट बनाएं (Create New Post)
@csrf
टाइटल (Title)
@error('title') {{ $message }} @enderror
कंटेंट (Content)
@error('content') {{ $message }} @enderror
इमेज (Image)
@endsection
resources/views/posts/show.blade.php
बनाएं और निम्नलिखित कोड डालें:@extends('layouts.app')
@section('content')
{{ $post->title }}
@if($post->image)
@endif
{{ $post->content }}
लेखक (Author): {{ $post->user->name }} | {{ $post->created_at->format('d M Y') }}
कमेंट्स (Comments)
@foreach($post->comments as $comment)
{{ $comment->content }}
द्वारा (By): {{ $comment->user->name }}
@endforeach
कमेंट जोड़ें (Add Comment)
@csrf
@error('content') {{ $message }} @enderror
@endsection
यूजर्स को पोस्ट्स पर कमेंट करने की सुविधा प्रदान करें।
php artisan make:controller CommentController
app/Http/Controllers/CommentController.php
में निम्नलिखित कोड डालें:namespace App\Http\Controllers;
use App\Models\Comment;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class CommentController extends Controller
{
public function store(Request $request)
{
$request->validate([
'content' => 'required',
'post_id' => 'required|exists:posts,id',
]);
Comment::create([
'content' => $request->content,
'post_id' => $request->post_id,
'user_id' => Auth::id(),
]);
return redirect()->back()->with('success', 'कमेंट जोड़ा गया!');
}
}
routes/web.php
में कमेंट रूट जोड़ें:use App\Http\Controllers\CommentController;
Route::post('/comments', [CommentController::class, 'store'])->name('comments.store')->middleware('auth');
ब्लॉग को प्रोफेशनल लुक देने के लिए:
resources/css/app.css
में कस्टम स्टाइल्स डालें:body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
}
.container {
max-width: 800px;
margin-top: 50px;
}
.card {
border-radius: 5px;
margin-bottom: 20px;
}
npm install
npm run dev
अपनी ब्लॉग वेबसाइट को टेस्ट करें।
http://localhost:8000/posts
खोलें।
अपने ब्लॉग को ऑनलाइन ले जाएं।
.env
फाइल को कॉन्फिगर करें।
लारवेल तेज, सुरक्षित, और स्केलेबल ब्लॉग सॉल्यूशन्स प्रदान करता है।
हां, इस लारवेल ब्लॉग ट्यूटोरियल हिंदी में गाइड के साथ शुरुआती डेवलपर्स आसानी से सीख सकते हैं।
इस गाइड के साथ 1-2 दिन। जटिल फीचर्स के लिए 1 सप्ताह।
हां, AddThis या ShareThis जैसे टूल्स का उपयोग करें।
Hostinger पर अपने प्रोजेक्ट को अपलोड करें।
इसల इस लारवेल ब्लॉग ट्यूटोरियल हिंदी में (Laravel Blog Tutorial in Hindi) के माध्यम से आपने सीखा कि Laravel का उपयोग करके पोस्ट्स, कमेंट्स, और डैशबोर्ड के साथ एक प्रोफेशनल ब्लॉग वेबसाइट कैसे बनाई जाती है। इस गाइड को फॉलो करें और अपना ब्लॉग शुरू करें। कोई सवाल हो? नीचे कमेंट करें। अपनी वेबसाइट को Hostinger पर होस्ट करें और इसे ऑनलाइन ले जाएं।
अगला क्या सीखें? (What to Learn Next?) Laravel Livewire, Vue.js, या Docker पर ट्यूटोरियल्स हिंदी में (Tutorials in Hindi) चाहिए? InHindi24.com पर और गाइड्स पढ़ें!
हाय, मैं एक फुल स्टैक डेवलपर (Full Stack Developer) हूँ, जिसके पास 7 साल का अनुभव (7 Years of Experience) है। मेरा जुनून है वेब डेवलपमेंट (Web Development) और कोडिंग (Coding) को आसान (Easy) और मजेदार बनाना, खासकर हिंदी भाषी ऑडियंस के लिए। मैं InHindi24.com पर हिंदी में टेक ट्यूटोरियल्स (Tech Tutorials in Hindi) शेयर करता हूँ, जिसमें लारवेल (Laravel), HTML, CSS, JavaScript, Python, और बहुत कुछ
Learn how to import large CSV files into a users table in Laravel using AJAX with a progress bar. This guide includes duplicate checking, chunk processing, and commented code.
Learn how to build a secure login, registration, and password reset system using Laravel Breeze. Step-by-step guide for beginners.
आज के डिजिटल युग में वेबसाइट बनाना (Build a Website) कोई जटिल काम नहीं है। यदि आप अपना बिज़नेस (Business) शुरू करना चाहते हैं, ब्लॉग (Blog) लिखना चाहते हैं, या पोर्टफोलियो (Portfolio) बनाना चाहते हैं, तो एक वेबसाइट आपको ऑनलाइन पहचान (Online Presence) प्रदान करती है। वेबसाइट कैसे बनाएं (Website Kaise Banaye)? यह सवाल हर शुरुआती (Beginner) के मन में आता है।