First of all, Everything is kind of confusing. There is a few tutorials and complete documentation but i feel like something is just not working way it should. For now I'm a little bit confused and discouraged. I learned how to write forms, how to make views with blade. How to menage migrations and even seeds. I know how to create new controller and simple routes.
But guys... I need some advice if you would answer...
I created a form with a view for example that form:
{{Form::open(array('url' => 'person/confirm'))}}
{{Form::label('firstname', 'Firstname:')}}
{{Form::text('firstname')}}
{{Form::label('lastname', 'Lastname:')}}
{{Form::text('lastname')}}
{{Form::label('company_name', 'Company name:')}}
{{Form::text('company_name')}}
{{Form::label('mail', 'Mail:')}}
{{Form::text('mail')}}
{{Form::label('phone', 'Phone:')}}
{{Form::text('phone')}}
{{Form::label('additional_phone', 'Additional phone:')}}
{{Form::text('additional_phone')}}
{{Form::label('city', 'City:')}}
{{Form::text('city')}}
{{Form::label('postalcode', 'Postalcode:')}}
{{Form::text('postalcode')}}
{{Form::label('address', 'Address:')}}
{{Form::text('address')}}
{{Form::label('notes', 'Notes:')}}
{{Form::text('notes')}}
{{Form::submit('Submit')}}
{{Form::close()}}
Nothing fancy, just a basic form. If I call submit, it will take me to person/confirm route. And it will be like this:
Route::post('person/confirm', function(){
$input = Input::all();
DB::table('humanity')->insert(
array('firstname' => $firstname);
);
}
I know that it is wrong.
How to get values from $input?
How to insert it to table correctly and safely?
Where is the best place to make query call?
It will be better to make query before routing starts or when next route will execute?
It would be good to create query in controller function and execute it in route then redirect to "message: Success"?
What exactly are classes and models and how can I use them?
I plan to write some system and day by day it makes me more sicker than satisfied. Something call me that I had hitched my wagon to a star.
Thank you in advice.
Ok so first off I suggest you look into Eloquent. Laravels ORM (http://laravel.com/docs/eloquent).
Eloquent will allow you to do this:
$human = new Human(Input::all());
$human->save();
But we can come back to that, your first question here is how to use the Input class. The real documentation can be found under Requests in the laravel documentation, but here's a brief guide.
Input::get('firstname'); //gets the first name
Input::get('lastname'); //get doesn't refer to the method, "get" will retrieve from post or get.
Input::all(); //will get you all input as an array - don't forget to validate
Input::except(array('csrf_token')); //will get you everything except for the 'csrf_token' as an array
One of the best ways to get help with Laravel is through the Laravel IRC channel, the community is great.
#Laravel is a place where many developers hang out and discuss the framework. Many people frequently pop their heads in looking for some help.
But, the real-time chat nature of IRC can be a refreshing contrast to posting on a forum and waiting for a reply.
The official community hub for laravel
Laravel.io has forums along with a plethora or useful tools such as the pastebin, you should become friends.
The other resource I suggest is Taylor's book
It's not free but it's well worth it.
Written by the creator of Laravel, this is the definitive guide to advanced application development with Laravel 4. Learn about dependency injection, interfaces, service providers, SOLID design, and more while exploring practical, real-world code examples. Whether you're building a robust, large application with the Laravel framework, or just want to sharpen your software design chops, this book will be of great value to you and your team.
It looks like you're in way over your head, especially since you asked what classes are.
I'd suggest putting Laravel (or any framework, for that matter) aside for a while until you have a solid understanding about object oriented programming and architectural patterns such as MVC / MVP. While Laravel resources will improve your knowledge quite a bit, it won't be nearly enough to create well structured applications.
Here are a couple of books that might be useful: