Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,017 members, 7,956,771 topics. Date: Monday, 23 September 2024 at 06:32 PM |
Nairaland Forum / Science/Technology / Programming / Populating Select Menu From Model In User Registration Form In Laravel (2019 Views)
Common Error In Laravel #1:solved File_put_contents Failed To Open Stream / Solution To Tokenmismatchexception Problem In Laravel 5.1 / Create A Nested Lists Of Categories In Laravel 5 (2) (3) (4)
Populating Select Menu From Model In User Registration Form In Laravel by maekhel(m): 3:47pm On Aug 28, 2015 |
Am trying to pass data from a model to be used to populate a select menu in my user registration form. What is the easy way to achieve this? |
Re: Populating Select Menu From Model In User Registration Form In Laravel by jidez007: 4:15pm On Aug 28, 2015 |
You would probably get all the data in your controller, then pass it to your view. eg. return view('signup')->with('schools', School::all()); Then in your view, just loop through and display it. eg
1 Like |
Re: Populating Select Menu From Model In User Registration Form In Laravel by maekhel(m): 4:20pm On Aug 28, 2015 |
Actually, I want to customize my users registration form and am using Laravel default auth controller and there is no option to pass data to the register view. |
Re: Populating Select Menu From Model In User Registration Form In Laravel by jidez007: 4:31pm On Aug 28, 2015 |
maekhel: yeah from your AuthController notice laravel is using AuthenticatesAndRegistersUsers trait. you can just override the getRegister method in the Controller. So you will add this method in your AuthController to override the default.
Also get in the habit of looking at some methods in the source codes sometimes, It really helps. |
Re: Populating Select Menu From Model In User Registration Form In Laravel by maekhel(m): 5:10pm On Aug 28, 2015 |
jidez007:This worked but I didn't know could do such in Laravel 5. |
Re: Populating Select Menu From Model In User Registration Form In Laravel by jidez007: 5:46pm On Aug 28, 2015 |
maekhel:You are welcome |
Re: Populating Select Menu From Model In User Registration Form In Laravel by micodon(m): 10:07pm On Aug 28, 2015 |
maekhel: The whole point of MVC is "separation of concerns". Your Model should fetch your data. Your views should display info to the users. The controller ties the model and the view together. It should control the process. To answer you question: if your model is named User, call it in your controller like so $this->data['users'] = User::get(); Then you can call your view like this return View::make('user', $this->data); Your data will be extracted and made available in the $users variable |
Re: Populating Select Menu From Model In User Registration Form In Laravel by dplumptre(m): 2:17am On Aug 29, 2015 |
maekhel: Yeah you can easily override the methods in the AuthenticatesAndRegistersUsers trait by copying the methods to your AuthController Class, easy navigation if you are using netbean as I am , just press ctrl and click on AuthenticatesAndRegistersUsers from the AuthController Class , so you can just easily modify both methods below to suit your purpose public function getRegister() { //code } public function postRegister(Request $request) { //code here } |
Re: Populating Select Menu From Model In User Registration Form In Laravel by maekhel(m): 2:36am On Aug 29, 2015 |
dplumptre:Thanks for the insight |
Re: Populating Select Menu From Model In User Registration Form In Laravel by maekhel(m): 9:17pm On Aug 29, 2015 |
How do I populate a select menu based on a previous select menu option in laravel. |
Re: Populating Select Menu From Model In User Registration Form In Laravel by jacob05(m): 9:41pm On Aug 29, 2015 |
maekhel:One thesame page |
Re: Populating Select Menu From Model In User Registration Form In Laravel by maekhel(m): 9:45pm On Aug 29, 2015 |
jacob05:yes |
Re: Populating Select Menu From Model In User Registration Form In Laravel by jacob05(m): 10:12pm On Aug 29, 2015 |
maekhel: use Javascript .... You'd need an API call too.. to fetch the result based on the selected select option |
Re: Populating Select Menu From Model In User Registration Form In Laravel by maekhel(m): 10:27pm On Aug 29, 2015 |
jacob05:How do create an api route |
Re: Populating Select Menu From Model In User Registration Form In Laravel by jacob05(m): 11:19pm On Aug 29, 2015 |
maekhel: It's just a normal route.. But instead of returning a view you return a "TYPE"... The "TYPE" can be a string, XML, and most preferably JSON eg return Response::json(array('name' => 'Steve', 'state' => 'CA')); |
(1) (Reply)
Get Our New Website Programming And Services At Special Discount This JULY. / Dairy Of Javascript Challenge / How To Make A Checkbox Required On An Email Form Read More
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 22 |