اذهب إلى المحتوى

محمد لارافيل

الأعضاء
  • المساهمات

    115
  • تاريخ الانضمام

  • تاريخ آخر زيارة

آخر الزوار

لوحة آخر الزوار معطلة ولن تظهر للأعضاء

إنجازات محمد لارافيل

عضو نشيط

عضو نشيط (3/3)

19

السمعة بالموقع

  1. لدي جدول للكتب ، عندما أنقر على اسم الكتاب على سبيل المثال قصة 1 ، سيظهر لي الأجزاء المرتبطة فيه أدناه ، مثل قصة الجزء 2 أو الجزء 3 ، أحاول ذلك من خلال like query أو group by حاولت هذه ولكن دون نتيجة public function book(Request $request) { $book = books::find($request->id); return [ 'book' => $book, 'more_books' => books:: ->whereNotIn('id', [$book->id]) ->where('title', 'like', '%' . $book->title. '%') ->get() ]; } output { "book": { "id": 40, "price": 20, "title": "Harry Potter Part 1" }, "more_books": [] } أرجو منكم المساعدة شكرا لكم
  2. أنا أستخدم طريقة PUT في أحد المسارات ولكن يظهر لي انه غير مسموح به Controller public function edit(Product $product) { return view('products_update', compact('product')); } public function edit(Product $product) { return view('products_update', compact('product')); } public function update(Request $request, $id) { $validatedData = $request->validate([ 'name' => 'required', 'desc' => 'required', 'price' => 'required|numeric', 'qty' => 'required', // Add more validation rules for other fields if needed ]); // Update the product $newTitle = $request->input('product_title'); $newDesc= $request->input('product_desc'); $newPrice= $request->input('product_price'); $newQty= $request->input('product_qty'); // Update other fields if needed //$product->save(); DB::update('update products set title = ?, desc = ?, price = ?, qty = ? where id = ?', [$newTitle, $newDesc, $newPrice, $newQty]); // Redirect to the index page or show a success message return redirect()->route('products.index')->with('success', 'Product updated successfully.'); } blade <form action="{{ route('products.edit', $product->id) }}" method="post"> @method('PUT') <!-- <input type="hidden" id="_token" value="{{ csrf_token() }}"> --> @csrf route Route::get('/products/{product}/edit', \[ProductController::class,'edit'\])-\>name('products.edit'); Route::put('/products/{id}', \[ProductController::class, 'update'\])-\>name('products.update'); أرجو منكم المساعدة شكرا لكم
  3. أريد إضافة معلمات بحث مخصصة إلى رابط الصفحة بجانب معلمة ترقيم الصفحات ولكن دائما ما يتم تحويلي الى المسار التالي But it redirects to https://localhost:8000/customers?page=2 أريد أن يكون كالتالي I need this to be http://localhost:8000/customers?key=ang&role=&from=&to=&page=2 هذا الكود لدي $users = User::orderBy('id', 'DESC') ->where($column, $operator, $num) ->where('email', 'LIKE', "%$key%") ->whereBetween('created_at', [$from, $to]) ->paginate(10); أرجو منكم المساعدة شكرا لكم
  4. لا يمكنني معرفة سبب عدم تحميل ال global scope مع factory أثناء الاختبارات: User class User extends Authenticatable { //... /** * The "booted" method of the model. */ protected static function booted(): void { static::addGlobalScope(new PreviousLogin); } /** * Get Audit relationship. */ public function previousLogin(): BelongsTo { return $this->belongsTo(Audit::class); } } PreviousLogin scope class PreviousLogin implements Scope { /** * {@inheritDoc} */ public function apply(Builder $builder, Model $model) { return $builder->addSelect([ 'previous_login_id' => Audit::select('id') ->whereColumn('user_id', 'users.id') ->where('event', UserLoggedIn::class) ->latest() ->skip(1) ->take(1), ]); } } DashboardController class DashboardController extends Controller { /** * Render view. */ public function __invoke(Request $request): Response { $previousLogin = $request->user()->previousLogin; return Inertia::render('Dashboard/Index', [ 'previous_login' => [ 'date' => $previousLogin?->created_at->format('d/m/Y H:i:s'), 'ip' => $previousLogin?->ip_address, 'agent' => $previousLogin?->agent, ], ]); } } /** * @test */ public function renders_view_and_displays_previous_login(): void { $audit = Audit::factory()->create([ 'created_at' => Carbon::now()->subHour(), ]); $this->actingAs(User::factory()->create()) ->get(route('dashboard')) ->assertInertia(fn(AssertableInertia $page) => $page ->has('previous_login', fn(AssertableInertia $page) => $page ->where('date', $audit->created_at->formated('d/m/Y H:i:s')) ->where('ip', $audit->ip_address) ->where('agent', $audit->agent) ->etc() ) ); } يظهر لدي الخطأ التالي Illuminate\Database\Eloquent\MissingAttributeException: The attribute [previous_login_id] either does not exist or was not retrieved for model [App\User\Models\User]. أرجو منكم المساعدة
  5. أنا أعمل على تطبيق دردشة باستخدام Laravel ، وأحتاج إلى مساعدة في فرز الرسائل بشكل صحيح. يعمل التطبيق دون ظهور اي مشكلة ولكنه يسترد جميع الرسائل التي أرسلها المستخدم الحالي إلى أي شخص ، بالإضافة إلى الرسائل المرسلة إلى المستخدم الحالي من قبل أي شخص. أريده فقط استرداد الرسائل بين المستخدم الحالي والمستخدم الذي يدردش معه. لدي جدولين للرسائل: الدردشات التي تخزن معرفات المرسل والمستلم ، والرسائل التي تخزن محتويات الرسالة. يرجى الاطلاع على الصورة المرفقة لهياكل الجدول. لقد قمت بتضمين مقتطفات للأكواد لإظهار العلاقات بين نماذج المستخدمين والمحادثات والرسائل. هل يمكن لأي شخص مساعدتي في هذه المشكلة من فضلكم؟ Users Model public function chats() { return $this->hasMany(Chat::class, 'recipient_id') ->orWhere(function($query) { $query->where('sender_id', '<>', $this->id) ->where('recipient_id', $this->id); }) ->orWhere(function($query) { $query->where('sender_id', $this->id) ->where('recipient_id', '<>', $this->id); })->orderBy('created_at', 'asc'); } Chats Model public function users() { return $this->belongsTo(User::class); } public function messages() { return $this->hasMany(Message::class, 'chat_id'); } Messages model public function chats() { return $this->belongsTo(Chat::class, 'chat_id'); } Messages Controller public function getMessages($username) { $host = User::where('username', $username)->first(); $user = Auth::user(); if($username !== $user->username && !Abilities::isBlocked($username) && Abilities::canBlock($username)) { $messages = $host->chats() ->with(['messages' => function ($query) { $query->orderBy('created_at', 'desc'); }]) ->where('recipient_id', $user->id) ->get() ->each(function($chat) { $chat->status = $chat->sender_id === Auth::user()->id ? "sent" : "received"; }); return response()->json([ "messages" => $messages, ]); } return response()->json(["messages" => "Unauthorized access."]); } Tables Structure
  6. لدي وظيفة التعديل هذه في الكونترولر ولكن يبدو أنها لا تقوم بالتعديل. هذا هو الكود الموديل StudentController أتأكد من وجود البيانات بساتخدام dd () Web.php هل يمكنكم مساعدتي؟ شكرا لكم
  7. لدي تنقل ديناميكي (جميع الأسماء والرموز والروابط وكل الأشياء الأخرى تأتي من الجدول). ولكن عند محاولة استخدام الرابط ، تلقيت خطأً بأن المسار [soon] غير معرف @foreach($categories as $item) <li class="sidebar-dropdown"> <a class="fw-bold" href="javascript:void(0)"><i class="uil {{ $item->icon }} me-2 d-inline-block"></i>{{ $item->title }}</a> <div class="sidebar-submenu"> @foreach($item['children'] as $child) <ul> <li><a href="{{ route($child->link)}}">{{ $child->title }}</a></li> </ul> @endforeach </div> </li> @endforeach web.php Route::prefix(config('admintw.prefix'))->middleware(['auth', 'verified', 'activeUser', 'IpCheckMiddleware'])->group(function () { Route::get('soon', \App\Http\Livewire\Admin\Miscellaneous\Comingsoon::class)->name('soon'); }); أرجو منكم المساعدة
  8. أحاول إنشاء نظام بريد إلكتروني باستخدام لارافيل ولكني أواجه بعض المشاكل أثناء استخدام mailtrap ، استغرقت الكثير من الوقت في البحث عن حل ولكن ما زلت أتلقى هذا الخطأ: "Connection could not be established with host "sandbox.smtp.mailtrap.io:2525": stream_socket_client(): Unable to connect to sandbox.smtp.mailtrap.io:2525 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)" في ملف .env MAIL_MAILER=smtp MAIL_HOST=sandbox.smtp.mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=************** MAIL_PASSWORD=************** MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}" هل يمكنكم مساعدتي؟
  9. أريد أزالة قيد unique من عمود البريد الإلكتروني باستخدام تهجيرات Laravel. هذا هو الكود الخاص بي: class AlterEmailToUsers extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('users', function (Blueprint $table) { $table->string('email')->unique(false)->nullable()->change(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('users', function (Blueprint $table) { $table->string('email')->nullable(false)->unique()->change(); }); } ولكن عندما اقوم بتنفيذ الامر php artisan migrate أحصل على الخطأ التالي SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'users_email_unique' (SQL: alter table `users` add unique `users_email_unique`(`email`)) أرجو منكم مساعدتي شكرا لكم
  10. أقوم بتطوير تطبيق Laravel 9 ، يستخدم التطبيق بعض الصور المخزنة في مجلد resources/images في ملفات Blade الخاصة بي ، أقوم بتضمين صور مثل <img src = "{{Vite :: asset ('resources / images / logo.png')}}" /> كل شيء يعمل بشكل جيد في وضع التطوير، ولكن عندما أقوم بتشغيل الأمر build وتشغيل التطبيق باستخدام php artisan serve ، أحصل على الخطأ التالي: Unable to locate file in Vite manifest: /resources/images/logo.png. محتويات الملف vite.config.js import { defineConfig } from 'vite'; import laravel from 'laravel-vite-plugin'; export default defineConfig({ plugins: [ laravel({ input: [ 'resources/css/app.css', 'resources/js/app.js', 'resources/images/logo.png', ], refresh: true, }), ], }); package.json { "private": true, "scripts": { "dev": "vite", "build": "vite build" }, "devDependencies": { "autoprefixer": "^10.4.13", "axios": "^1.1.2", "laravel-vite-plugin": "^0.7.2", "lodash": "^4.17.19", "postcss": "^8.4.21", "tailwindcss": "^3.2.4", "vite": "^4.0.0" }, "dependencies": { "alpinejs": "^3.12.0", "flowbite": "^1.6.4", "xlsx": "^0.18.5" } } لقد تحققت من ملف manifest.json الذي تم إنشاؤه بعد الأمر build، ويمكن العثور على الصورة فيه ، لذلك لا أفهم سبب ظهور الخطأ لي: "resources/images/logo.png": { "file": "assets/logo-4ed993c7.js", "isEntry": true, "src": "resources/images/logo.png" }, هل يمكنكم المساعدة؟
  11. عند تشغيل npm run dev ، يظهر لي خطأ: PS D:\xampp\htdocs\LoginGoogle> npm run dev > @ dev D:\xampp\htdocs\LoginGoogle > vite failed to load config from D:\xampp\htdocs\LoginGoogle\vite.config.js error when starting dev server: Error: Cannot find module 'node:path' Require stack: - D:\xampp\htdocs\LoginGoogle\node_modules\vite\dist\node-cjs\publicUtils.cjs - D:\xampp\htdocs\LoginGoogle\node_modules\vite\index.cjs - D:\xampp\htdocs\LoginGoogle\vite.config.js - D:\xampp\htdocs\LoginGoogle\node_modules\vite\dist\node\chunks\dep-934dbc7c.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! @ dev: `vite` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @ dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: حاولت تنفيذ الاوامر التالية composer require laravel/jetstream php artisan jetstream:install livewire npm install npm run dev هل يمكنكم مساعدتي؟
  12. لدي حقلين اختياريين فقط في حالة عدم وجود كلاهما: $rules = [ 'initial_page' => 'required_with:end_page|integer|min:1|digits_between: 1,5', 'end_page' => 'required_with:initial_page|integer|min:2|digits_between:1,5' ]; الآن ، يجب أن تكون end_page أكبر من initial_page. كيف أقوم بمثل هذا الفلتر؟
  13. أريد إنشاء علاقة متعددة الأشكال وتسمح بأن تكون فارغة مثال: Schema::create('ps_assistances', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('assistance_number', 50)->nullable(); $table->morphs('assitanceable')->nullable(); }); لكن هذا المثال يعيد قيمة فارغة عند تحديد ->nullable() أحاول إنشاء _type و _id يدويا ويعمل بشكل جيد كالتالي Schema::create('ps_assistances', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('assistance_number', 50)->nullable(); $table->string('assitanceable_type')->nullable(); $table->unsignedBigInteger('assitanceable_id')->nullable(); }); هل يمنكم مساعدتي؟
  14. باتباع مستندات Laravel (إرفاق Laravel pivot بالجدول بقيم متعددة) لا يمكنني رؤية القيم المرفقة دون استدعاء () fresh في النموذج. هل هناك طريقة أفضل لإرفاق هذه النماذج؟ لا أرغب في استخدام () fresh للنموذج بأكمله لأنه تم تحميل العلاقات الأخرى بالفعل. سيؤدي القيام بذلك إلى إعادة الاستعلام وانا لا اريد ذلك Attaching $productsToSync = $productsCollection->mapWithKeys(fn ($subscriptionProduct) => [ $subscriptionProduct->id => [ 'quantity' => $subscriptionProduct->quantity, 'amount' => $subscriptionProduct->amount, 'item_id' => $subscriptionProduct->item_id, ] ])->toArray(); $subscription->products()->attach($productsToSync); // This exception passes and is NOT thrown --> SubscriptionProducts are in the DB throw_unless( SubscriptionProducts::whereSubscriptionId($subscription->id)->count() > 0, new \Exception("No SubscriptionProducts in DB?!) ); // required NOT to throw ... but it refreshes and subsequently requires re-querying // any already loaded relationships // $subscription = $subscription->fresh(); throw_if( $subscription->products->isEmpty(), new \Exception("Products not attached to subscription WTF!?!") ); Subscription Class class Subscription extends Model { public function products(): BelongsToMany { return $this->belongsToMany(Products::class, 'subscription_products', 'subscription_id', 'product_id') ->using(SubscriptionProducts::class) ->as('subscriptionProducts') ->withPivot('id', 'item_id', 'quantity', 'amount'); } } أرجو منكم المساعدة
  15. أجريت بعض اختبارات الأداء ، كانت واجهة DB أسرع بكثير من Eloquent للعديد من عبارات SQL, على سبيل المثال SELECT ، UPDATE ، DELETE ، INSERT. إذن لماذا شخص ما يستخدم Laravel Eloquent الأبطأ بدلاً من واجهة DB الأسرع ؟ شكرا لكم مقدما على الاجابة
×
×
  • أضف...