jeudi 12 mai 2016

returning null when getting the values of the paramater of create method in laravel

I have a custom route that accepts parameter. Which is:

Route::get('reservation/{id}/create', 
        ['as' => 'reservation.create', 'uses' => 'ReservationController@create'
]);

I have this variable protected $student_id. That id is being assigned to the parameter of the create method of ReservationController as seen below:

class ReservationController extends Controller
{
    protected $student_id;

    public function index()
    {
        return $this->student_id;
    }

    public function create($id)
    {
        $this->student_id = $id;
        $subjects = Subject::with('sections')->get();

        return view('reservation.form',compact('subjects'));
    }

    public function store(Request $request)
    {

        $subject = new Reservation();

        $subject->section_subject_id = $request->sectionSubjectId;

        $subject->student_id = $this->student_id;

        $subject->save();

    }
}

When returning the $id parameter on the create method I get the exact id number. I also assigned that $id with the $student_id. But when assigning the $student_id on the store method I get null value. I know that I am doing wrong here, can someone please help me on this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire