Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

masumluf's avatar

Laravel Controller edit function issue.

Hello Developers,I got an issue at my controller edit function. I dont see any value if i dd($brightStudent) This is my controller code below,

<?php

namespace App\Http\Controllers;

use App\Model\BrightStudent;
use Carbon\Carbon;
use Illuminate\Http\Request;

class BrightStudentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $total_student = BrightStudent::all()->count();

        $brightstudents = BrightStudent::paginate(5);

        return view('Admin.BrightStudentlist', compact('brightstudents', 'total_student'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
       return view('Admin.BrightStudent');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $file=$request->pic;


        $profileImage = str_pad(mt_rand(0, 999999), 6, '0', STR_PAD_LEFT).time() . '.' . $file->getClientOriginalName();

        $destinationPath = public_path('/images/'); // upload path
        $file->move($destinationPath, $profileImage);
        $data= ["bright_student_name"=>$request->bright_student_name,"bright_student_details"=>$request->bright_student_details,"bright_student_photo"=>$profileImage,"created_at"=>Carbon::now(),"updated_at"=>Carbon::now()];
        BrightStudent::create($data);
    }


    /**
     * Display the specified resource.
     *
     * @param  \App\Model\BrightStudent  $brightStudent
     * @return \Illuminate\Http\Response
     */
    public function show(BrightStudent $brightStudent)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Model\BrightStudent  $brightStudent
     * @return \Illuminate\Http\Response
     */
    public function edit(BrightStudent $brightStudent)
    {
        dd($brightStudent);
        //return view('Admin.EditBrightStudent', compact('brightStudent'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Model\BrightStudent  $brightStudent
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, BrightStudent $brightStudent)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Model\BrightStudent  $brightStudent
     * @return \Illuminate\Http\Response
     */
    public function destroy(BrightStudent $brightStudent)
    {
        //
    }
}

and this is the link where I came from edit url

<a class="dropdown-item" href="/brightstudent/{{$brightstudent->id}}/edit"> <i class="fas fa-user-edit nav-icon"></i> Edit</a>

Url like that

http://127.0.0.1:8000/brightstudent/2/edit

I don't see any value when i try dd($brightStudent). I have value in my mysql database.

0 likes
4 replies
siangboon's avatar

most likely your route issue, you have to put the exact same name as your parameter, in this case, brightStudent

Route::get('/brightstudent/{brightStudent}/edit', 'BrightStudentController@edit');
Wraith's avatar

Don't do this in that way. I suggest

Route::get('/brightstudent/{brightStudent}/edit', 'BrightStudentController@edit')->name('bright-student');

<a class="dropdown-item" href="{{ route('bright-student', [$brightstudent]) }}"> <i class="fas fa-user-edit nav-icon"></i> Edit</a>

because you using model in controller

public function edit(BrightStudent $brightStudent)

so Laravel will take ID

masumluf's avatar

Sorry it was my database naming issue. thank you for your time.

Please or to participate in this conversation.