ايمن ميلاد نشر الثلاثاء في 20:42 أرسل تقرير نشر الثلاثاء في 20:42 السلام عليكم لدي مشكلة اثناء زيارة صفحة تظهر فارغة Route::get('Department', [DepartmentController::class, 'index'])->name('Department'); Route::get('Department/create', [DepartmentController::class, 'create']); Route::get('Department/{id}', [DepartmentController::class, 'show']); Route::post('Department', [DepartmentController::class, 'store']); Route::get('Department/{id}/edit', [DepartmentController::class, 'edit']); Route::put('Department/{id}',[DepartmentController::class, 'update']); Route::delete('Department/{id}',[DepartmentController::class, 'destroy']); كود صفحة index @extends('layouts.master'); @section('title') الاقسام @stop @section('css') @stop @section('title_page1') لوحة التحكم @stop @section('title_page2') الأقسام @stop @section('content') <div class="box"> <div class="box-header"> <h4> <a href="/department/create">إضافة قسم</a></h4> </div> <!-- /.box-header --> <div class="box-body no-padding"> <table class="table direction table-striped"> <th>#</th> <th>اسم القسم</th> <th>تاريخ الانشاء</th> @foreach ($departments as $index => $department) <tr> <td>{{ $department->id_dept }}</td> {{-- <td>{{ $department->Name_dept }}</td> --}} <td><a href="/department/<?=$department->id_dept ?>"><?=$department->Name_dept ?></a></td> <td>{{ $department->created_at }}</td> </tr> @endforeach </table> </div> <!-- /.box-body --> </div> @endsection @section('scripts') @stop دوال داخل controller <?php namespace App\Http\Controllers; use App\Models\Department; use Illuminate\Http\Request; class DepartmentController extends Controller { public function index() { $departments = Department::all(); return view('department.index', compact('departments')); } public function show() { } public function create() { return view ('department.create'); } public function store() { } public function edit($id) { return view ('department.edit'); } public function update($id) { } public function destroy($id) { } } صفحة create @extends('layouts.master'); @section('title') الاقسام @stop @section('css') @stop @section('title_page1') الاقسام @stop @section('title_page2') اضافة قسم @stop @section('content') <form action="/Department" method="post"> <div class="form-group"> <label for="name">اسم القسم</label> <input type="text" name="name" id="name" class="form-control"> </div> <div class="form-group"> <button class="btn btn-primary">حفظ</button> </div> </form> @stop @section('scripts') @stop لماذا عندما ازور صفحة create يظهر 404 2 اقتباس
0 محمد عاطف17 نشر الثلاثاء في 20:44 أرسل تقرير نشر الثلاثاء في 20:44 وعليكم السلام ورحمة الله وبركاته. إن خطأ 404 يعني أن العنوان الذي تذهب إليه غير موجود لديك . أي أن ال url غير موجود في ملف web.php . هل يمكنك توضيح ما هو العنوان الذي تذهب إليه ويعطيك 404 ؟ ولكن أولا في هذا السطر : بتاريخ 14 دقائق مضت قال ايمن ميلاد: <h4> <a href="/department/create">إضافة قسم</a></h4> يرجى إستبدال department ب Department فمن الممكن أن المشكلة هنا : <h4> <a href="/Department/create">إضافة قسم</a></h4> ولكن من الأفضل إعطاء أسماء لل routes وإستخدام دالة route حيث من الممكن أن المشكلة هنا فإذا كان الموقع الخاص بك ال domain ليس هو ال root فستحدث مشكلة في ذلك. فمثلا لنفرض أن موقعك المحلي هكذا : http://localhost/test/ هنا ستحدث مشكلة إذا ضغطت على الرابط لأنه سيتوجه إلى localhost أى سيكون العنوان هكذا : http://localhost/Department/create لاحظ كيف تم حذف test وهو إسم المشروع لديك من العنوان . لهذا إما أن تستخدام دالة route أو ان تقوم بجعل الرابط هكذا في صفحة index : <h4> <a href="create">إضافة قسم</a></h4> 1 اقتباس
0 عبد الوهاب بومعراف نشر الثلاثاء في 21:15 أرسل تقرير نشر الثلاثاء في 21:15 لاحظ أن هنالك عدم تطابق لحالة الأحرف في كلمة Department بين تعريف المسارات واستخدامها ففي ملف التوجيهات (Routes) المسارات معرفة بحرف كبير: Route::get('Department/create', [DepartmentController::class, 'create']); بينما في رابط الصفحة (index.blade.php) الرابط يستخدم حرف صغير: <a href="/department/create">إضافة قسم</a> وفي المتحكم نجد أن view يستخدم حرف صغير: return view('department.create'); فالمسارات حساسة لحالة الأحرف و /Department/create مختلف تماما عن /department/create وعندما تضغط على الرابط في صفحة index سيقوم المتصفح بإرسال طلب إلى /department/create (بحرف صغير) لكن Laravel يبحث عن مسار معرف باسم Department/create (بحرف كبير) ولا يجده فيعرض خطأ 404. لذا قم بتعديل جميع المسارات لتستخدم نفس حالة الأحرف والأفضل استخدام أحرف صغيرة للمسارات لأن هذا هو الأسلوب الشائع في Laravel: Route::get('department', [DepartmentController::class, 'index'])->name('department.index'); Route::get('department/create', [DepartmentController::class, 'create'])->name('department.create'); Route::post('department', [DepartmentController::class, 'store'])->name('department.store'); 1 اقتباس
0 ايمن ميلاد نشر منذ 10 ساعة الكاتب أرسل تقرير نشر منذ 10 ساعة لماذا عندما ازور صفحة تظهر Page Expired @extends('layouts.master') @section('title') الاقسام @stop @section('css') <head> <meta name="csrf-token" content="{{csrf_token()}}"> </head> <style> .form-group { display: flex; flex-direction: column; align-items: center; margin-top: } #name { width: 50%; } </style> @stop @section('title_page1') الاقسام @stop @section('title_page2') اضافة قسم @stop @section('content') <form action="/Department" method="post"> <input type="hidden" name="_token" value="{{csrf_token()}}"> <div class="form-group"> <label for="name">اسم القسم</label> <input type="text" name="name" id="name" class="form-control"> </div> <div class="form-group"> <button class="btn btn-primary">حفظ</button> </div> </form> @stop @section('scripts') @stop public function store(Request $request) { $department = new Department(); $department->Name_dept = $request->input('name'); $department->save(); return redirect(); } ممكن حل مشكلة 1 اقتباس
0 Mustafa Suleiman نشر منذ 9 ساعة أرسل تقرير نشر منذ 9 ساعة بتاريخ 26 دقائق مضت قال ايمن ميلاد: لماذا عندما ازور صفحة تظهر Page Expired @extends('layouts.master') @section('title') الاقسام @stop @section('css') <head> <meta name="csrf-token" content="{{csrf_token()}}"> </head> <style> .form-group { display: flex; flex-direction: column; align-items: center; margin-top: } #name { width: 50%; } </style> @stop @section('title_page1') الاقسام @stop @section('title_page2') اضافة قسم @stop @section('content') <form action="/Department" method="post"> <input type="hidden" name="_token" value="{{csrf_token()}}"> <div class="form-group"> <label for="name">اسم القسم</label> <input type="text" name="name" id="name" class="form-control"> </div> <div class="form-group"> <button class="btn btn-primary">حفظ</button> </div> </form> @stop @section('scripts') @stop public function store(Request $request) { $department = new Department(); $department->Name_dept = $request->input('name'); $department->save(); return redirect(); } بسبب استخدامك لـ return redirect(); بدون تحديد مسار، حيث سيحاول لارافيل العودة للصفحة السابقة التي تتطلب إعادة إرسال البيانات POST وذلك يسبب Page Expired. غيّر return redirect(); إلى مسار محدد كالتالي: return redirect()->route('Departments.index'); وعدل المسار حسب ما هو موجو لديك، من المفترض أن يكون: Route::get('/Departments', [DepartmentController::class, 'index'])->name('Departments.index'); أيضًا إضافة CSRF Token في النموذج <form > @csrf </form> 1 اقتباس
0 ايمن ميلاد نشر منذ 9 ساعة الكاتب أرسل تقرير نشر منذ 9 ساعة لازالت تظهر مشكلة <?php use App\Http\Controllers\DepartmentController; use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); })->name('/'); Route::get('/Department', [DepartmentController::class, 'index'])->name('Department'); Route::get('Department/create', [DepartmentController::class, 'create']); Route::get('Department/{id}', [DepartmentController::class, 'show']); Route::post('Department', [DepartmentController::class, 'store']); Route::get('Department/{id}/edit', [DepartmentController::class, 'edit']); Route::put('Department/{id}', [DepartmentController::class, 'update']); Route::delete('Department/{id}', [DepartmentController::class, 'destroy']); <?php namespace App\Http\Controllers; use App\Models\Department; use Illuminate\Http\Request; class DepartmentController extends Controller { public function index() { $departments = Department::all(); $deptcount=Department::count(); return view('department.index', compact('departments','deptcount')); } public function show() {} public function create() { return view('department.create'); } public function store(Request $request) { $department = new Department(); $department->Name_dept = $request->input('name'); $department->save(); return redirect()->route('Departments.index'); } public function edit($id) { return view('department.edit'); } public function update($id) {} public function destroy($id) {} } @extends('layouts.master') @section('title') الاقسام @stop @section('css') <style> .form-group { display: flex; flex-direction: column; align-items: center; margin-top: 20px; } #name { width: 50%; } </style> @stop @section('title_page1') الاقسام @stop @section('title_page2') اضافة قسم @stop @section('content') <form action="/Department" method="post"> @csrf <div class="form-group"> <label for="name">اسم القسم</label> <input type="text" name="name" id="name" class="form-control"> </div> <div class="form-group"> <button class="btn btn-primary">حفظ</button> </div> </form> @stop @section('scripts') @stop 1 اقتباس
0 Mustafa Suleiman نشر منذ 8 ساعة أرسل تقرير نشر منذ 8 ساعة بتاريخ 27 دقائق مضت قال ايمن ميلاد: لازالت تظهر مشكلة <?php use App\Http\Controllers\DepartmentController; use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); })->name('/'); Route::get('/Department', [DepartmentController::class, 'index'])->name('Department'); Route::get('Department/create', [DepartmentController::class, 'create']); Route::get('Department/{id}', [DepartmentController::class, 'show']); Route::post('Department', [DepartmentController::class, 'store']); Route::get('Department/{id}/edit', [DepartmentController::class, 'edit']); Route::put('Department/{id}', [DepartmentController::class, 'update']); Route::delete('Department/{id}', [DepartmentController::class, 'destroy']); <?php namespace App\Http\Controllers; use App\Models\Department; use Illuminate\Http\Request; class DepartmentController extends Controller { public function index() { $departments = Department::all(); $deptcount=Department::count(); return view('department.index', compact('departments','deptcount')); } public function show() {} public function create() { return view('department.create'); } public function store(Request $request) { $department = new Department(); $department->Name_dept = $request->input('name'); $department->save(); return redirect()->route('Departments.index'); } public function edit($id) { return view('department.edit'); } public function update($id) {} public function destroy($id) {} } @extends('layouts.master') @section('title') الاقسام @stop @section('css') <style> .form-group { display: flex; flex-direction: column; align-items: center; margin-top: 20px; } #name { width: 50%; } </style> @stop @section('title_page1') الاقسام @stop @section('title_page2') اضافة قسم @stop @section('content') <form action="/Department" method="post"> @csrf <div class="form-group"> <label for="name">اسم القسم</label> <input type="text" name="name" id="name" class="form-control"> </div> <div class="form-group"> <button class="btn btn-primary">حفظ</button> </div> </form> @stop @section('scripts') @stop اسم المسار لديك هو Department لذا نُعدل الكود إلى: return redirect()->route('Department.index'); ثم تعديل اسم المسار إلى Department.index: Route::get('/Department', [DepartmentController::class, 'index'])->name('Department.index'); اقتباس
0 ايمن ميلاد نشر منذ 8 ساعة الكاتب أرسل تقرير نشر منذ 8 ساعة لازالت نفس مشكلة <?php use App\Http\Controllers\DepartmentController; use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); })->name('/'); Route::get('/Department', [DepartmentController::class, 'index'])->name('Department'); Route::get('Department/create', [DepartmentController::class, 'create']); Route::get('Department/{id}', [DepartmentController::class, 'show']); Route::post('Department', [DepartmentController::class, 'store']); Route::get('Department/{id}/edit', [DepartmentController::class, 'edit']); Route::put('Department/{id}', [DepartmentController::class, 'update']); Route::delete('Department/{id}', [DepartmentController::class, 'destroy']); للعلم مجلد وداخله صفحة index <?php namespace App\Http\Controllers; use App\Models\Department; use Illuminate\Http\Request; class DepartmentController extends Controller { public function index() { $departments = Department::all(); return view('department.index', compact('departments')); } public function show() {} public function create() { return view('department.create'); } public function store(Request $request) { $department = new Department(); $department->Name_dept = $request->input('name'); $department->save(); return redirect()->route('Department.index'); } public function edit($id) { return view('department.edit'); } public function update($id) {} public function destroy($id) {} } @extends('layouts.master') @section('title') الاقسام @stop @section('css') <style> .form-group { display: flex; flex-direction: column; align-items: center; margin-top: 20px; } #name { width: 50%; } </style> @stop @section('title_page1') الاقسام @stop @section('title_page2') اضافة قسم @stop @section('content') <form action="/Department" method="post"> @csrf <div class="form-group"> <label for="name">اسم القسم</label> <input type="text" name="name" id="name" class="form-control"> </div> <div class="form-group"> <button class="btn btn-primary">حفظ</button> </div> </form> @stop @section('scripts') @stop اقتباس
0 Mustafa Suleiman نشر منذ 8 ساعة أرسل تقرير نشر منذ 8 ساعة بتاريخ 7 دقائق مضت قال ايمن ميلاد: لازالت نفس مشكلة <?php use App\Http\Controllers\DepartmentController; use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); })->name('/'); Route::get('/Department', [DepartmentController::class, 'index'])->name('Department'); Route::get('Department/create', [DepartmentController::class, 'create']); Route::get('Department/{id}', [DepartmentController::class, 'show']); Route::post('Department', [DepartmentController::class, 'store']); Route::get('Department/{id}/edit', [DepartmentController::class, 'edit']); Route::put('Department/{id}', [DepartmentController::class, 'update']); Route::delete('Department/{id}', [DepartmentController::class, 'destroy']); للعلم مجلد وداخله صفحة index <?php namespace App\Http\Controllers; use App\Models\Department; use Illuminate\Http\Request; class DepartmentController extends Controller { public function index() { $departments = Department::all(); return view('department.index', compact('departments')); } public function show() {} public function create() { return view('department.create'); } public function store(Request $request) { $department = new Department(); $department->Name_dept = $request->input('name'); $department->save(); return redirect()->route('Department.index'); } public function edit($id) { return view('department.edit'); } public function update($id) {} public function destroy($id) {} } @extends('layouts.master') @section('title') الاقسام @stop @section('css') <style> .form-group { display: flex; flex-direction: column; align-items: center; margin-top: 20px; } #name { width: 50%; } </style> @stop @section('title_page1') الاقسام @stop @section('title_page2') اضافة قسم @stop @section('content') <form action="/Department" method="post"> @csrf <div class="form-group"> <label for="name">اسم القسم</label> <input type="text" name="name" id="name" class="form-control"> </div> <div class="form-group"> <button class="btn btn-primary">حفظ</button> </div> </form> @stop @section('scripts') @stop ما زلت لم تقم بتغيير المسار في web.php إلى: Route::get('/Department', [DepartmentController::class, 'index'])->name('Department.index'); اقتباس
0 ايمن ميلاد نشر منذ 7 ساعة الكاتب أرسل تقرير نشر منذ 7 ساعة (معدل) لازالت تظهر نفس مشكلة تم التعديل في منذ 7 ساعة بواسطة ايمن ميلاد 1 اقتباس
0 Mustafa Suleiman نشر منذ 7 ساعة أرسل تقرير نشر منذ 7 ساعة بتاريخ 7 دقائق مضت قال ايمن ميلاد: لازالت تظهر نفس مشكلة أرفق مجلد المشروع لتفقد ما المشكلة. 1 اقتباس
السؤال
ايمن ميلاد
السلام عليكم لدي مشكلة اثناء زيارة صفحة تظهر فارغة
كود صفحة index
دوال داخل controller
صفحة create
لماذا عندما ازور صفحة create يظهر 404
11 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.