Laravel about Requests

好久不见. 提交于 2019-12-25 06:27:12

问题


i am new in programing laravel. so here I will not ask about my problems but I am here just want to ask how to use laravel. here I would like to ask how to use:

Determining If an Input Value Is Present in laravel. and what it does?

thanks ^^


回答1:


Laravel is really a good MVC Framework. I can suggest you some source from where you can get better understanding of Laravel Framework.

  1. https://laravel.com/docs/5.2
  2. https://laracasts.com/skills/laravel

For simple example - How to use Laravel after installation

  • Go to path using terminal ex. /var/www/laravel/project
  • Go to - /var/www/laravel/project/resources/views
  • Create a directory test and create a file index.php
  • Create a controller - php artisan make:controller TestController
  • Create a function testGet() and return view - return view('test.index'); //test is directory and index is file
  • Create a function testPost(Request $request) and to get data use $data = $request->all(); and then print this data.
  • Create a model with migration file - php artisan make:model Test --migration
  • Go to route file - /var/www/laravel/project/app/Http/routes.php
  • Add line Route::get('/test', 'TestController@testGet');
  • Add line Route::post('/test', 'TestController@testPost');

Now check GET request to your project http://project/test it will call testGet function. POST request http://project/test?name=Adam will call testPost function and will print your name.




回答2:


as said in the comments you better check laracasts! its the laravel school anyway to anwser your question, its simple

View

<input type="text" name="fname">

Controller

public function doingstuff (Illuminate\Http\Request $request) {
    if ($request->has('fname')) {
        // a man gotta do what a man gotta do here
    }
 }

smooth huh? :3



来源:https://stackoverflow.com/questions/36764181/laravel-about-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!