0 Chihab Hedidi نشر 1 يوليو 2024 أرسل تقرير نشر 1 يوليو 2024 المشكلة بسبب متغير غير معرف في العرض (view). من الصور التي أرفقتها، الخطأ يأتي من ملف العرض student.blade.php حيث لا يتم تمرير متغير $student بشكل صحيح من الـ Controller إلى العرض. في الصورة الأولى، في ملف الـ Controller StudentController، لاحظت أنك قمت بتعريف المتغير $student كالتالي: $student = student::all(); لكن عندما تقوم بتمرير المتغير إلى العرض، يجب أن تستخدم الطريقة الصحيحة وهي: $students = Student::all(); return view('student.index', compact('students')); لاحظ أنني قمت بتغيير اسم المتغير من $student إلى $students ليعكس أن هناك مجموعة من الطلاب، ويجب تمريره بنفس الاسم إلى العرض. ثم في ملف العرض student.blade.php، يجب عليك استخدام المتغير $students بنفس الاسم كالتالي: @foreach ($students as $student) <tr> <td>{{ $student->name }}</td> </tr> @endforeach تأكد من أن الأسماء المستخدمة في العرض تتطابق مع الأسماء التي قمت بتمريرها من الـ Controller، حاول تعديل الكود وتحقق مما إذا كانت المشكلة قد حلت. اقتباس
0 محمد عاطف17 نشر 1 يوليو 2024 أرسل تقرير نشر 1 يوليو 2024 الخطأ أنك تقوم بإستخدام نفس المتغير في حلقة foreach وهذا خطأ حيث أن foreach لن تعرف أي متغير تقصده وتريد إستخدامه . ولحل تلك المشكلة نتبع الخطوات التالية : أولا يجب عليك تمرير المتغير من ال controlles بإسم students هكذا : $students = student:all(); return view('student.index',compact('students')); وفي ملف ال blade يكون كالتالي : @foreach ($students as $student) اقتباس
0 ايمن ميلاد نشر 1 يوليو 2024 الكاتب أرسل تقرير نشر 1 يوليو 2024 بتاريخ 2 دقائق مضت قال Chihab Hedidi: المشكلة بسبب متغير غير معرف في العرض (view). من الصور التي أرفقتها، الخطأ يأتي من ملف العرض student.blade.php حيث لا يتم تمرير متغير $student بشكل صحيح من الـ Controller إلى العرض. في الصورة الأولى، في ملف الـ Controller StudentController، لاحظت أنك قمت بتعريف المتغير $student كالتالي: $student = student::all(); لكن عندما تقوم بتمرير المتغير إلى العرض، يجب أن تستخدم الطريقة الصحيحة وهي: $students = Student::all(); return view('student.index', compact('students')); لاحظ أنني قمت بتغيير اسم المتغير من $student إلى $students ليعكس أن هناك مجموعة من الطلاب، ويجب تمريره بنفس الاسم إلى العرض. ثم في ملف العرض student.blade.php، يجب عليك استخدام المتغير $students بنفس الاسم كالتالي: @foreach ($students as $student) <tr> <td>{{ $student->name }}</td> </tr> @endforeach تأكد من أن الأسماء المستخدمة في العرض تتطابق مع الأسماء التي قمت بتمريرها من الـ Controller، حاول تعديل الكود وتحقق مما إذا كانت المشكلة قد حلت. هذا كود العرض @foreach ($students as $student) <tr> <td>{{$student->name}} </td> <td>{{$student->num_std}}</td> <td>{{$student->adress_std}}</td> <td>{{$student->email_std}}</td> <td>{{$student->phone}}</td> </tr> @endforeach هذا كود كنترول class StudentController extends Controller { /** * Display a listing of the resource. */ public function index() { // $students = student::all(); return view('student.index', compact('students')); } /** * Show the form for creating a new resource. */ public function create() { // } 1 اقتباس
0 محمد عاطف17 نشر 1 يوليو 2024 أرسل تقرير نشر 1 يوليو 2024 بتاريخ 4 دقائق مضت قال ايمن ميلاد: هذا كود العرض @foreach ($students as $student) <tr> <td>{{$student->name}} </td> <td>{{$student->num_std}}</td> <td>{{$student->adress_std}}</td> <td>{{$student->email_std}}</td> <td>{{$student->phone}}</td> </tr> @endforeach هذا كود كنترول class StudentController extends Controller { /** * Display a listing of the resource. */ public function index() { // $students = student::all(); return view('student.index', compact('students')); } /** * Show the form for creating a new resource. */ public function create() { // } هل تم حل الخطأ أ, تغير الخطأ إلى خطأ آخر ؟ وأيضا هل قمت بإستيراد النموذج student أم هذا هو كود ملف ال controller كاملا ؟ اقتباس
0 Chihab Hedidi نشر 1 يوليو 2024 أرسل تقرير نشر 1 يوليو 2024 بتاريخ 1 دقيقة مضت قال ايمن ميلاد: هذا كود العرض @foreach ($students as $student) <tr> <td>{{$student->name}} </td> <td>{{$student->num_std}}</td> <td>{{$student->adress_std}}</td> <td>{{$student->email_std}}</td> <td>{{$student->phone}}</td> </tr> @endforeach هذا كود كنترول class StudentController extends Controller { /** * Display a listing of the resource. */ public function index() { // $students = student::all(); return view('student.index', compact('students')); } /** * Show the form for creating a new resource. */ public function create() { // } الكود يبدو صحيحا، تأكد من أن النموذج (Model) الخاص بك مكتوب بالأحرف الكبيرة كالتالي: Student وليس student، و في الـ Controller، تأكد من أنك تقوم باستيراد النموذج بشكل صحيح: use App\Models\Student; class StudentController extends Controller { public function index() { $students = Student::all(); return view('student.index', compact('students')); } } و في الأخير جرب مسح التخزين المؤقت للعرض: php artisan view:clear اقتباس
0 ايمن ميلاد نشر 1 يوليو 2024 الكاتب أرسل تقرير نشر 1 يوليو 2024 لازالت نفس مشكلة مكتوب اسم مودل صغير حرف s اقتباس
0 محمد عاطف17 نشر 1 يوليو 2024 أرسل تقرير نشر 1 يوليو 2024 بتاريخ 1 دقيقة مضت قال ايمن ميلاد: لازالت نفس مشكلة إذا أعتقد ان الكود لا يدخل في StudentController . قم بإضافة سطر dd في دالة index هكذا : public function index() { // $students = student::all(); dd($students); return view('student.index', compact('students')); } وأخبرني بالنتيجة اقتباس
0 ايمن ميلاد نشر 1 يوليو 2024 الكاتب أرسل تقرير نشر 1 يوليو 2024 بتاريخ 2 دقائق مضت قال محمد عاطف17: إذا أعتقد ان الكود لا يدخل في StudentController . قم بإضافة سطر dd في دالة index هكذا : public function index() { // $students = student::all(); dd($students); return view('student.index', compact('students')); } وأخبرني بالنتيجة لازالت نفس مشكلة اقتباس
0 محمد عاطف17 نشر 1 يوليو 2024 أرسل تقرير نشر 1 يوليو 2024 بتاريخ 2 دقائق مضت قال ايمن ميلاد: لازالت نفس مشكلة إذا هناك مشكلة في ملف web.php حيث يتم توجيه العنوان إلى مكان أخر غير StudentController قم بتنفيذ الأمر التالي : php artisan optimize:clear والمحاولة مرة أخري و إذا ما زالت المشكلة موجودة فيجب إرفاق مجلد المشروع اقتباس
0 ايمن ميلاد نشر 1 يوليو 2024 الكاتب أرسل تقرير نشر 1 يوليو 2024 لازالت نفس مشكلة هذا ملف web.php <?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\StudentController; Route::get('/', function () { return view('welcome'); }); Route::get('/student', function () { return view('student'); }); اقتباس
0 محمد عاطف17 نشر 1 يوليو 2024 أرسل تقرير نشر 1 يوليو 2024 بتاريخ 1 دقيقة مضت قال ايمن ميلاد: لازالت نفس مشكلة هذا ملف web.php <?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\StudentController; Route::get('/', function () { return view('welcome'); }); Route::get('/student', function () { return view('student'); }); لاحظ أن الخطأ من الأساس في ملف web.php . حيث أنك لم ترسل العنوان إلى StudentController . يجب أن يكون الكود كالتالي : use Illuminate\Support\Facades\Route; use App\Http\Controllers\StudentController; Route::get('/', function () { return view('welcome'); }); Route::get('/student',[StudentController::class, 'index']); وقم بحذف سطر dd الذى قمنا بكتابته في ملف StudentController اقتباس
0 ايمن ميلاد نشر 1 يوليو 2024 الكاتب أرسل تقرير نشر 1 يوليو 2024 gpms.rar بتاريخ 5 دقائق مضت قال محمد عاطف17: لاحظ أن الخطأ من الأساس في ملف web.php . حيث أنك لم ترسل العنوان إلى StudentController . يجب أن يكون الكود كالتالي : use Illuminate\Support\Facades\Route; use App\Http\Controllers\StudentController; Route::get('/', function () { return view('welcome'); }); Route::get('/student',[StudentController::class, 'index']); وقم بحذف سطر dd الذى قمنا بكتابته في ملف StudentController مشكلة اخري اقتباس
0 محمد عاطف17 نشر 1 يوليو 2024 أرسل تقرير نشر 1 يوليو 2024 بتاريخ 30 دقائق مضت قال ايمن ميلاد: gpms.rar 30.38 MB · 4 تنزيلات مشكلة اخري هذا ملف StudentController.php : <?php namespace App\Http\Controllers; use App\Models\student; use Illuminate\Http\Request; class StudentController extends Controller { /** * Display a listing of the resource. */ public function index() { // $students = student::all(); return view('student', compact('students')); } /** * Show the form for creating a new resource. */ public function create() { // } /** * Store a newly created resource in storage. */ public function store(Request $request) { // } /** * Display the specified resource. */ public function show(student $student) { // } /** * Show the form for editing the specified resource. */ public function edit(student $student) { // } /** * Update the specified resource in storage. */ public function update(Request $request, student $student) { // } /** * Remove the specified resource from storage. */ public function destroy(student $student) { // } } وهذا ملف web.php : <?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\StudentController; Route::get('/', function () { return view('welcome'); }); Route::get('/student',[StudentController::class, 'index']); 1 اقتباس
0 ايمن ميلاد نشر 3 يوليو 2024 الكاتب أرسل تقرير نشر 3 يوليو 2024 لماذا لا تظهر الصفحة اخي محمد عاطف اقتباس
السؤال
ايمن ميلاد
15 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.