简体   繁体   中英

Can not pass request parameter to controller from route in laravel 5

I have

public function checkCookie(Request $request) {

// do something 
}

in my controller and I am trying to call it from routes.php with

Route::get('mypage',function(){
    $a=new App\Http\Controllers\indexController;
    $a->checkCookie();               
});

but I can't pass request parameter. What am I missing?

Here's what this should look like:

routes.php

<?php
Route::get('/mypage', 'IndexController@checkCookie');

Controllers/IndexController.php

<?php 

namespace App\Http\Controllers;

use Request;

class IndexController extends Controller {

    public function checkCookie()
    {
        $data = Request::only('myvariable');
        dd($data);
    }
}

thanks for helps!!! finally i could pass param with

Route::get('mypage',function(Request $request){
    $a=new App\Http\Controllers\indexController;
    $b=$a->checkCookie($request);
    if(!empty($b)){
        return view('mypage');
    }
});

and did these configs in my .env

DB_HOST=localhost
DB_DATABASE='db_name'
DB_USERNAME='root'
DB_PASSWORD=''
DB_PORT=3306

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM