Support the ongoing development of Laravel.io →
posted 9 years ago
Authentication
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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' ); }
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Halnex halnex Joined 29 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.