0

I'm making an admin panel that can edit users but i keep getting the same issue. When i click to edit i got 404 not found page. Form for updating user code:

@extends("backend.shared.backend_theme")
@section("title","User Module")
@section("subtitle","Update Users")
@section("btn_url",url()->previous())
@section("btn_label","Go back")
@section("btn_icon","arrow-left")
@section("content")
    <form action="{{url('/users/$user->user_id')}}" method="POST" autocomplete="off" novalidate>
        @csrf
        @method("PUT")
        <input type="hidden" name="user_id" value="{{$user->user_id}}">
        <div class="row">
            <div class="col-lg-6">
                <div class="mt-2">
                    <x-input label="Ad Soyad" placeholder="Ad soyad giriniz" field="name" value="{{$user->name}}"/>
                </div>
            </div>
            <div class="col-lg-6">
                <div class="mt-2">
                    <x-input label="E-posta giriniz" placeholder="E-posta giriniz" field="email" type="email"
                             value="{{$user->email}}"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-6">
                <x-checkbox field="is_admin" label="Yetkili Kullanıcı" checked="{{$user->is_admin == 1}}"/>
            </div>
        </div>
        <div class="row">
            <div class="col-12">
                <button type="submit" class="btn btn-primary mt-2"><span data-feather="save"></span> KAYDET</button>
            </div>
        </div>
    </form>
@endsection

UserController code:

public function edit(User $user): View
    {
        return view("backend.users.update_form", ["user"=>$user]);
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(CategoryRequest $request, User $user): RedirectResponse
    {
        $data = $this->prepare($request, $user->getFillable());
        $user->fill($data);
        $user->save();

        return Redirect::to($this->returnUrl);
    }

The url it gave is http://localhost:8000/users/$user->user_id/edit. But doesnt show the editing page it says 404 not found

  • `url('/users/$user->user_id')` should have double quotes so the variables are processed. – ceejayoz Apr 10 '23 at 20:57
  • Then there will be 2 double quotes and it give error on vs code – Hilal Derya Eryılmaz Apr 10 '23 at 22:04
  • you can also use route name method https://laravel.com/docs/10.x/routing#named-routes . declare route name to url in web.php then use that route name in blade file. it will generates url for you. you can see this example https://stackoverflow.com/a/35752263/14344959 – Harsh Patel Apr 11 '23 at 05:05

0 Answers0