to get the id of the current logged in user, all you need to do is Auth::user()->id. no need to pass it using a hidden field.
Alright, I created the new controller "ListingsController.php" and a new model "Listing.php" but now when I submit the data in my form, I get the error: Controller method not found.
Code to ListingsController.php
<? class ListingsController extends BaseController { protected $layout = 'layouts/main'; public function getCreate() { $this->layout->content = View::make('listings/create'); } public function listingCreate() { $validator = Validator::make(Input::all(), Listing::$rules); if ($validator->passes()) { $listing = new Listing; $listing->status = Input::get('status'); $listing->listingfor = Input::get('listingfor'); $listing->propertystatus = Input::get('propertystatus'); $listing->propertytype = Input::get('propertytype'); $listing->userid = Auth::user()->id; $listing->save(); return Redirect::to('listings/create')->with('message', '<div class="alert alert-success">Your property has been added.</div>'); } else { return Redirect::to('listings/create')->with('message', 'The following errors occurred')->withErrors($validator)->withInput(); } } } Code to Listing.php model <?php use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; class Listing extends Eloquent implements UserInterface, RemindableInterface { public static $rules = array( 'status'=>'required', 'listingfor'=>'required', 'propertystatus'=>'required', 'propertytype'=>'required' ); }Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community