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

السؤال

نشر

السلام عليكم عندما اضغط علي زر حفظ تظهر صفحة PAGE EXPIRED

اكواد المستخدمة لدي 

<?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) {}
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Department extends Model
{
    protected $fillable=[
       'Name_dept',
    ] ;
}
@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="{{ route('Department.index') }}" 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 type="submit" class="btn btn-primary">حفظ</button>
        </div>
    </form>
@stop
@section('scripts')

@stop
@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

ممكن حل مشكلة 

Recommended Posts

  • 0
نشر

وعليكم السلام ورحمة الله وبركاته.

لاحظ أنك في النموذج form تقوم بإرسال الطلب إلى Department.index ولكن هل هذا هو العنوان الصحيح الذي يقوم بتوجيه الطلب إلى دالة store لديك في المتحكم DepartmentController ؟

إذا كان كذلك إذا المشكلة لديك في الدالة store حيث لاحظ أنك في نهاية الدالة تقوم بإعادة التوجيه إلى  Department.index هنا:

بتاريخ 28 دقائق مضت قال ايمن ميلاد:
        return redirect()->route('Department.index');

لذلك يرجى إعادة التوجيه إلى المسار الصحيح حيث هكذا أنت تعيد التوجيه إلى نفس العنوان الذي يؤدى إلى الدالة store .

ويفضل تغير إسم المسار الخاص بالحفظ من Department.index إلى Department.store

  • 0
نشر

يعني تقصد form  تصبح هكذا 

<form action="{{ route('Department.store') }}" method="post">
@csrf       
        <div class="form-group">
            <label for="Name_dept">اسم القسم</label>
            <input type="text" name="Name_dept" id="Name_dept" class="form-control">
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-primary">حفظ</button>
        </div>
    </form>

وكود حفظ يصبح هكدا 

public function store(Request $request)
    {
        $department = new Department();
        $department->Name_dept = $request->input('name');
        $department->save();
        echo "تم حفظ ";
    }

 

  • 0
نشر
بتاريخ 3 دقائق مضت قال ايمن ميلاد:

يعني تقصد form  تصبح هكذا 

<form action="{{ route('Department.store') }}" method="post">
@csrf       
        <div class="form-group">
            <label for="Name_dept">اسم القسم</label>
            <input type="text" name="Name_dept" id="Name_dept" class="form-control">
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-primary">حفظ</button>
        </div>
    </form>
 

وكود حفظ يصبح هكدا 

public function store(Request $request)
    {
        $department = new Department();
        $department->Name_dept = $request->input('name');
        $department->save();
        echo "تم حفظ ";
    }
 

 

ليس تماما .

أولا يجب تغير إسم ال route في ملف web.php إلى Department.store .

ويجب إعادة التوجيه في نهاية الدالة store وليس فقط echo.

بتاريخ 4 دقائق مضت قال ايمن ميلاد:
        echo "تم حفظ ";

أى هنا يجب أن تقوم بالتوجيه redirect إلى العنوان الذي يذهب للدالة index لديك في المتحكم يمكنك النظر في ملف web.php إلى إسم ال route وتغيره.

  • 0
نشر

تقصد هكدا 

Route::post('Department', [DepartmentController::class, 'store'])->name('Department.store');
public function store(Request $request)
    {
        $department = new Department();
        $department->Name_dept = $request->input('name');
        $department->save();
        return redirect()->route('Department.index');

       
    }
<form action="{{ route('Department.index') }}" 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 type="submit" class="btn btn-primary">حفظ</button>
        </div>
    </form>

 

تظهر مشكلة لازالت

  • 0
نشر
بتاريخ 9 دقائق مضت قال ايمن ميلاد:

يرجى إستخدام نفس الأكواد في هذا المشروع حيث الخطأ ليس في الأكواد .

بل لأنك قمت بتفعيل ال cache ولهذا فإن التعديلات التي تقوم بها لا يتم تطيبقها لأنه تم عمل cache للأكواد السابقة .

ولإيقاف ذلك يرجى تنفيذ الأمر التالي :

php artisan optimize:clear

ستجد كل شئ يعمل معك الآن.

  • 0
نشر
بتاريخ 2 دقائق مضت قال ايمن ميلاد:

نفدت امر لزالت مشكلة 

من المفترض أن المشروع يعمل بشكل صحيح فقد قمت بتجربته لدى . 

يرجى تحميل برنامج anydesk وإرسال العنوان الخاص بك في رسالة على الخاص لدي و ستجده باللون الأحمر في البرنامج وذلك للدخول على جهازك وحل المشكلة لك.

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...