laravel : Accessing The Request from URL using get method

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.




<?php
namespace 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

Route::get('/category', 'CategoryController@index')->name('category');
Run with php artisan serve and pass the variable
http://127.0.0.1:8000/category?name=test

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...