Reputation: 6798
Hello im new in Laravel and im not able to add data to database from form. I have simple one view with only one form. Controller have 2 actions (for view form and for creating db rows).
app/routes.php
Route::get('/', 'FrontendController@index');
Route::post('/', 'FrontendController@submit');
app/views/index.blade.php
{{Form::open(array('action'=>'FrontendController@submit','class'=>'form-horizontal','role'=>'form'))}}
{{Form::text('nazev_firmy',Input::old('nazev_firmy'), array('class'=>'form-control'))}}
{{Form::submit('Send', array('class'=>'btn btn-primary submit'))}}
{{Form::close()}}
/app/controllers/FrontendController.php
class FrontendController extends BaseController {
public function index()
{
return View::make('index');
}
public function submit()
{
$inzerat = new Inzerat;
$inzerat->nazev_firmy = Input::post('nazev_firmy');
$inzerat->save();
return View::make('index');
}
}
app/models/Inzerat.php
<?php
class Inzerat extends Eloquent {
protected $table = 'inzeraty';
public $timestamps = false;
}
ERROR AFTER CLICK ON SUBMIT BUTTON
Call to undefined method Illuminate\Http\Request::post()
Im using Laravel 4.0
What i have done wrong here ? Thank you for your help.
Upvotes: 0
Views: 3798
Reputation: 2330
In laravel, you use ::get() to retrieve all input from the request. You just need to change
$inzerat->nazev_firmy = Input::post('nazev_firmy');
To:
$inzerat->nazev_firmy = Input::get('nazev_firmy');
Upvotes: 5