Laravel controller: Difference between revisions
From AWVVO
Jump to navigationJump to search
Created page with "== action template == <syntaxhighlight lang="php" copy> public function index() { $data = []; return response()->json($data); } </syntaxhighlight>" |
|||
Line 6: | Line 6: | ||
return response()->json($data); | return response()->json($data); | ||
} | |||
</syntaxhighlight> | |||
== Get request parameters == | |||
use Illuminate\Http\Request; | |||
<syntaxhighlight lang="php" copy> | |||
public function index(Request $request) | |||
{ | |||
// Get a specific parameter (with default value if not present) | |||
$param = $request->input('key', 'default_value'); | |||
// Get all parameters as an array | |||
$allParams = $request->all(); | |||
// Access query string parameters specifically | |||
$queryParam = $request->query('key', 'default_value'); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 16:32, 18 January 2025
action template
public function index()
{
$data = [];
return response()->json($data);
}
Get request parameters
use Illuminate\Http\Request;
public function index(Request $request)
{
// Get a specific parameter (with default value if not present)
$param = $request->input('key', 'default_value');
// Get all parameters as an array
$allParams = $request->all();
// Access query string parameters specifically
$queryParam = $request->query('key', 'default_value');
}