In this tutorial learn how to accessing the request from url using get method and pass value from url to controller in laravel.
Create controller CategoryController.php in controller
To obtain an instance of the current HTTP request via dependency injection,you should type-hint the Illuminate\Http\Request class on your controller method.
Dependency Injection & Route Parameters
If your controller method is also expecting input from a route parameter you should list your route parameters after your other dependencies. For example, if your route is defined like so:
web.php
Create controller CategoryController.php in controller
To obtain an instance of the current HTTP request via dependency injection,you should type-hint the Illuminate\Http\Request class on your controller method.
<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;class CategoryController extends Controller{/*** Show the application dashboard.** @return \Illuminate\Contracts\Support\Renderable*/public function index(Request $request){echo "==>". $name = $request->input('name');}}
Dependency Injection & Route Parameters
If your controller method is also expecting input from a route parameter you should list your route parameters after your other dependencies. For example, if your route is defined like so:
web.php
Run with php artisan serve and pass the variableRoute::get('/category', 'CategoryController@index')->name('category');
http://127.0.0.1:8000/category?name=test
No comments:
Post a Comment