doulai7239 2014-04-14 00:45
浏览 60
已采纳

在Laravel 4中进行查询呼叫的最佳位置在哪里?

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.

  • 写回答

2条回答 默认 最新

  • drvpvmz16241016 2014-04-14 01:20
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端