0

I want to retrieve last inserted id from my table students and pass to view. But i don't know how to? I have used following code for inserting data inside my table.

public function store(Request $request)
    {

        $input=Request::all();

        Student::create($input);
        $students=Student::all();
        $M_fees=M_fees::all();
        return view('students.fees',compact('students','M_fees'));

    } 

Can anyone help me?

Anon
  • 523
  • 1
  • 7
  • 25

1 Answers1

0

Actually its figured out! Just store the model in a variable like:

  $student= Student::create($input);
        $students=Student::all();
        $insertedId= $student->id;
        return $insertedId;

It works pretty well!

Anon
  • 523
  • 1
  • 7
  • 25