0

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.

1 Answer 1

5

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.