duandi8838 2016-10-05 01:21
浏览 20
已采纳

将数据从textarea传递到函数和路由

I am new to web development and have been learning Laravel. I am following a video tutorial series (https://laracasts.com/series/laravel-5-from-scratch). In the series they use a text are to pass data to a post controller. I would like the user to input their name. If they are in the database, then they are taken to a user's page. I have the Model, database, and migrations working.

For the index page, routing:

Route::get('/','UserController@index');
Route::get('/user', UserController@checked');
Route::get('/accesdenied','UserController@accessdenied');

index view:

    <h1>Welcome</h1>
    <h1>Please enter User Name</h1>
    <form>
       <div>
           <textarea name="body"></textarea> 
           <button type="submit">Access</button>
       </div>     
    </form>

controller:

class UserController extends Controller
{
    public function index()
    {
        return view('users.index');//view is in users folder
    }
    public function check(Request $request)
    {
        $user = DB::table('users')->where('name', $request->body)->first();
        if (isset($user))
            return view(‘users.checked’, compact(‘user’));
        else
            return view('users.accessdenied');//is it right to direct to a page back to a controller?
    }   
    public function accessdenied(Request $request)
    {
        //try again is same as index page with text added
        return view('users.tryagain');
    }   
} 

I have no idea what to pass from the form.

Thank you.

  • 写回答

1条回答 默认 最新

  • douzhun8615 2016-10-05 01:32
    关注

    just do a small change

    <h1>Welcome</h1>
    <h1>Please enter User Name</h1>
    <form method="get" action="{{ action('UserController@checked') }}">
       <div>
           <textarea name="body"></textarea> 
           <button type="submit">Access</button>
       </div>     
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号