Skip to content
Advertisement

Passing more than one variables from different controllers to a single view in Laravel 8

I need to pass two variables from two different controllers to a view and display the different values from the array variables to two different html form’s select options in Laravel 8. But Laravel doesn’t seem to allow pass two differnt variable to a single view.

How do I slove this?

Please find the error screenshot from this link.

Controllers involved: TimeController, CourseController

Time Controller:

JavaScript

CourseController:

JavaScript

Routes:

JavaScript

View:

JavaScript

Advertisement

Answer

So based on your comment I understand your issue. And you don’t need Two controllers and seperate routes.

Create a New controller with name of StudentEnrollmentController by running

php artisan make:controller StudentEnrollmentController and paste the below code into controller

JavaScript

Add following line to routes/web.php

JavaScript

Now visit the URL enrollmentForm it will Display the form without errors.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement