{"id":21142006,"url":"https://github.com/ag-sanjjeev/laravel-notes","last_synced_at":"2026-04-28T09:31:35.168Z","repository":{"id":177977732,"uuid":"507817718","full_name":"ag-sanjjeev/laravel-notes","owner":"ag-sanjjeev","description":"This repository contains notes and topics to learn and practice Laravel PHP Framework.","archived":false,"fork":false,"pushed_at":"2025-03-08T12:53:58.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-01T05:48:14.383Z","etag":null,"topics":["documentation","framework","laravel","mvc","notes","php"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ag-sanjjeev.png","metadata":{"files":{"readme":null,"changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-06-27T08:05:07.000Z","updated_at":"2025-03-03T12:43:18.000Z","dependencies_parsed_at":"2025-12-29T12:08:06.124Z","dependency_job_id":null,"html_url":"https://github.com/ag-sanjjeev/laravel-notes","commit_stats":null,"previous_names":["ag-sanjjeev/laravel-9-docs","ag-sanjjeev/laravel-notes"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ag-sanjjeev/laravel-notes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ag-sanjjeev%2Flaravel-notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ag-sanjjeev%2Flaravel-notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ag-sanjjeev%2Flaravel-notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ag-sanjjeev%2Flaravel-notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ag-sanjjeev","download_url":"https://codeload.github.com/ag-sanjjeev/laravel-notes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ag-sanjjeev%2Flaravel-notes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32375239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T09:24:15.638Z","status":"ssl_error","status_checked_at":"2026-04-28T09:24:15.071Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["documentation","framework","laravel","mvc","notes","php"],"created_at":"2024-11-20T07:40:14.045Z","updated_at":"2026-04-28T09:31:35.157Z","avatar_url":"https://github.com/ag-sanjjeev.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Notes\nThis repository contains notes and topics related to Laravel PHP Framework. This is gives some useful comments and code samples. For complete usage, refer offical documentation.   \n\n# **Project Setup:**\n\n## Laravel Installation:\n\n  `composer global require laravel/installer`\n\n## Creating new laravel project\n\n  `laravel new example-app`\n\n## Create project with git repository\n\n  `laravel new example-app --git`\n\n  `laravel new example-app --git --branch=\"main\"`\n\n## Serving / Running project\n\n  `cd example-app`\n\n  `php artisan serve`\n\n## Maintenance mode\n\n  `php artisan down --refresh=15`\n\n  *refresh the page every 15 seconds*\n\n  `php artisan down --retry=60`\n\n## Bypassing Maintenance mode\n\n  `php artisan down --secret=\"1234542a-246b-4b66-afa1-dd72a4c43515\"`\n\n  *via following URL with secret key :* \u003chttps://example.com/1234542a-246b-4b66-afa1-dd72a4c43515\u003e\n\n## Pre-rendering Maintenance mode\n\n  `php artisan down --render=\"errors::503\"`\n\n## Redirect Maintenance mode\n\n  `php artisan down --redirect=/`\n\n## Disabling Maintenance mode\n\n  `php artisan up`\n\n## Storage directory mapping or symbolic link\n\n  `php artisan storage:link`\n\n  *this will generate symbolic link for the publicly available directory that storage/app/public into public/storage.*\n\n## Get available make artisan commands\n\n  `php artisan list make`\n\n  *That commands originated from console directory inside app directory.*\n\n---\n\n# **Important Steps to follow when deploying:**\n\n  This will have all essential technique, performance optimization and security features implementation with it.\n\n  Here are some as follows:\n    1. Server Requirement to run application,\n    2. Server configuration (example: pointing to public/index.php),\n    3. Autoloader optimization,\n    4. configuration cache (env file will never used after that),\n    5. route cache,\n    6. view cache,\n\n  all before process set debug mode false.\n\n  Follow the bellow link or check for any other versions.\n\n  \u003chttps://laravel.com/docs/9.x/deployment\u003e\n\n\n---\n\n# **Routings:**\n\n## Route structures:\n\n  The first parameter is referred to the request and second to the callback in different method as given further below methods.\n\n  ```php  \n  Route::get($uri, $callback);\n  Route::post($uri, $callback);\n  Route::put($uri, $callback);\n  Route::patch($uri, $callback);\n  Route::delete($uri, $callback);\n  Route::options($uri, $callback);\n  ```\n\n## Method 1:\n\n  Returning text for the request.\n\n  ```php\n  use Illuminate\\Support\\Facades\\Route;\n\n  Route::get('/greeting', function () {\n    return 'Hello World';\n  });\n  ```\n\n## Method 2:\n\n  Returning to controller method for the request.\n\n  use App\\Http\\Controllers\\UserController;\n\n  Route::get('/user', [UserController::class, 'index']);\n\n## Method 3:\n\n  This will check request method as mention in the first parameter array.\n\n  ```php\n  Route::match(['get', 'post'], '/', function () {\n    //\n  });\n  ```\n\n## Method 4:\n\n  This will take request with any of the request method.\n\n  ```php\n  Route::any('/', function () {\n    //\n  });\n  ```\n\n## Redirecting Route:\n\n  Simple redirection for the request URL.\n\n  ```php\n  Route::redirect('/here', '/there');\n  ```\n\n  Redirection with status code for the requested URL.\n\n  ```php\n  Route::redirect('/here', '/there', 301);\n  ```\n\n  Permanent Redirection with status code 301 for the requested URL.\n\n  ```php\n  Route::permanentRedirect('/here', '/there');\n  ```\n\n## Method 5:\n\n  Returning the view page / file for the requested URL.\n\n  ```php\n  Route::view('/welcome', 'welcome');\n  ```\n\n  This will additionally pass some data to it.\n\n  ```php\n  Route::view('/welcome', 'welcome', ['name' =\u003e 'Taylor']);\n  ```\n\n## Method 6:\n\n  Routes with required URL parameter.\n\n  ```php\n  Route::get('/user/{id}', function ($id) {\n      return 'User '.$id;\n  });\n  ```\n\n  Routes with many parameter required and that parameter should be positional.\n\n  ```php\n  Route::get('/posts/{post}/comments/{comment}', function ($postId, $commentId) {\n    //\n  });\n  ```\n\n## Method 7:\n\n  Route parameter with dependency injection. Here, Request is dependency. That is injected with URL parameter.\n\n  ```php\n  use Illuminate\\Http\\Request;\n\n  Route::get('/user/{id}', function (Request $request, $id) {\n    return 'User '.$id;\n  });\n  ```\n\n## Method 8:\n\n  Route with optional URL parameters.\n\n  ```php\n  Route::get('/user/{name?}', function ($name = 'Guest') {\n      return 'User name : ' . $name;\n  });\n  ```\n\n## Method 9:\n\n  Route URL parameters with regular expression constrains. That accepts request only if valid.\n\n  ```php\n  Route::get('/user/{name}', function ($name) {\n      //\n  })-\u003ewhere('name', '[A-Za-z]+');\n\n  Route::get('/user/{id}', function ($id) {\n      //\n  })-\u003ewhere('id', '[0-9]+');\n\n  Route::get('/user/{id}/{name}', function ($id, $name) {\n      //\n  })-\u003ewhere(['id' =\u003e '[0-9]+', 'name' =\u003e '[a-z]+']);\n\n  Route::get('/user/{id}/{name}', function ($id, $name) {\n      //\n  })-\u003ewhereNumber('id')-\u003ewhereAlpha('name');\n\n  Route::get('/user/{name}', function ($name) {\n      //\n  })-\u003ewhereAlphaNumeric('name');\n\n  Route::get('/user/{id}', function ($id) {\n      //\n  })-\u003ewhereUuid('id');\n\n  Route::get('/category/{category}', function ($category) {\n      //\n  })-\u003ewhereIn('category', ['movie', 'song', 'painting']);\n  ```\n\n## Route URL Parameter Global Constrains:\n\n  It need to define inside boot method in the App\\Providers\\RouteServiceProvider Class.\n  and this will recognize id URL parameter wherever is defined also need not to call where constrain for that parameters in routes\\web.php file.  \n\n  ```php\n  Route::pattern('id', '[0-9]+');\n  ```\n\n## Explicit allowing forward slashes as URL parameter:\n\n  This will take {search} parameter for the link example.com/search/food/rise as food/rise.\n\n  ```php\n  Route::get('/search/{search}', function ($search) {\n    return $search;\n  })-\u003ewhere('search', '.*');\n  ```\n\n## Creating named routes:\n\n  ```php\n  Route::get('/user/profile', function () {\n    //\n  })-\u003ename('profile');\n  ```\n\n  This URL will be named as profile and Wherever Profile name used that URL again generated.\n\n  ```php\n  $url = route('profile');\n  $url = route('profile', ['id' =\u003e 1]); # for URL parameter.\n  return redirect()-\u003eroute('profile');\n\n  Inspecting / Checking current route:\n\n  if ($request-\u003eroute()-\u003enamed('profile')) {\n      //\n  }\n  ```\n\n## Route Group with middleware:\n\n  This will apply middleware for all other routes inside this group.\n\n  ```php\n  Route::middleware(['first', 'second'])-\u003egroup(function () {\n    Route::get('/', function () {\n        // Uses first \u0026 second middleware...\n    });\n\n    Route::get('/user/profile', function () {\n        // Uses first \u0026 second middleware...\n    });\n  });\n  ```\n\n## Route Group with controller:\n\n  This will target specific controller for all other routes inside this group.    \n\n  ```php\n  Route::controller(OrderController::class)-\u003egroup(function () {\n      Route::get('/orders/{id}', 'show');\n      Route::post('/orders', 'store');\n  });\n  ```\n\n## Sub-domain routing with Route Group:\n\n  The route group can target and apply all other additional information to all routes with it for sub-domain purpose.\n\n  ```php\n  Route::domain('{account}.example.com')-\u003egroup(function () {\n      Route::get('user/{id}', function ($account, $id) {\n          //\n      });\n  });\n  ```\n\n## Route Prefix:\n\n  The route group can be used for creating prefix route for all other routes inside it.\n  Here prefixes URL with admin.\n\n  ```php\n  Route::prefix('admin')-\u003egroup(function () {\n      Route::get('/users', function () {\n          // Matches The \"/admin/users\" URL\n      });\n  });\n  ```\n\n## Route Name Prefix:\n\n  The route group can be used for creating prefix named route for all other routes inside it.\n  Here Prefixes name for named routes with admin.\n\n  ```php\n  Route::name('admin.')-\u003egroup(function () {\n      Route::get('/users', function () {\n          // Route assigned name \"admin.users\"...\n      })-\u003ename('users');\n  });\n\n  $url = route('admin.users');\n  ```\n\n## Custom 404 Route:\n\n  This will handle 404 not found by this method.\n\n  ```php\n  Route::fallback(function () {\n    //\n  });\n  ```\n\n## Route Rate Limiting:\n\n  This will limit traffic to specific route / URL. and this can be defined inside App\\Providers\\RouteServiceProvider class.\n\n  ```php\n  use Illuminate\\Cache\\RateLimiting\\Limit;\n  use Illuminate\\Http\\Request;\n  use Illuminate\\Support\\Facades\\RateLimiter;\n\n  protected function configureRateLimiting()\n  {\n      RateLimiter::for('global', function (Request $request) {\n          return Limit::perMinute(1000);\n      });\n  }\n\n  RateLimiter::for('global', function (Request $request) {\n      return Limit::perMinute(1000)-\u003eresponse(function (Request $request, array $headers) {\n          return response('Custom response...', 429, $headers);\n      });\n  });\n  ```\n\n## Route Details:\n\n  Get current route, name and action.\n\n  ```php\n  $route = Route::current();\n  $name = Route::currentRouteName();\n  $action = Route::currentRouteAction();\n  ```\n\n## Route related artisan commands:\n\n  Get all routes available.\n\n  `php artisan route:list`\n\n  Get all routes available with middleware.\n\n  `php artisan route:list -v`\n\n  Get all routes created by developer.\n\n  `php artisan route:list --except-vendor`\n\n  Get all routes available by application itself.\n\n  `php artisan route:list --only-vendor`\n\n  Route Caching:\n\n  `php artisan route:cache`\n\n  Route Cache Clearing:\n\n  `php artisan route:clear`\n\n---\n\n# **Middlewares:**\n\n  Middlewares provide convenient way to filters requests and perform some actions based on conditions.\n  example: Authentication middleware can check requested user is logined or not. if the user is not loggined then redirected to login page.\n\n## Creating Middlewares:\n\n  Middlewares can be created via following artisan command.\n  EnsureTokenIsValid class created inside app/Http/Middleware.\n\n  `php artisan make:middleware EnsureTokenIsValid`\n\n## Registering Middlewares:\n\n  If middleware need to be used then need to registered inside app/Http/Kernel.php in the routeMiddleware.\n\n## Applying Middleware:\n\n  Apply single middleware for specific request URL.\n\n  ```php\n  Route::get('/profile', function () {\n    //\n  })-\u003emiddleware('auth');\n  ```\n\n  Apply multiple middlewares for specific request URL.\n\n  ```php\n  Route::get('/', function () {\n      //\n  })-\u003emiddleware(['first', 'second']);\n  ```\n\n  Apply middleware without specifying the name but fully qualified class.\n\n  ```php\n  use App\\Http\\Middleware\\EnsureTokenIsValid;\n\n  Route::get('/profile', function () {\n      //\n  })-\u003emiddleware(EnsureTokenIsValid::class);\n  ```\n\n## Excluding middleware from middleware route group.\n\n  ```php\n  Route::middleware([EnsureTokenIsValid::class])-\u003egroup(function () {\n      Route::get('/', function () {\n          //\n      });\n\n      Route::get('/profile', function () {\n          //\n      })-\u003ewithoutMiddleware([EnsureTokenIsValid::class]);\n  });\n  ```\n\n## Exclude the route from global middleware group.\n\n  ```php\n  Route::withoutMiddleware([EnsureTokenIsValid::class])-\u003egroup(function () {\n      Route::get('/profile', function () {\n          //\n      });\n  });\n  ```\n\n## Global Middlewares:\n\n  Group of global middleware group can be registered inside App\\Providers\\RouteServiceProvider for corresponding web.php and or api.php route files.\n  That route group can be applied as following ways.\n\n  ```php\n  Route::get('/', function () {\n      //\n  })-\u003emiddleware('web');\n\n  Route::middleware(['web'])-\u003egroup(function () {\n      //\n  });\n  ```\n\n## Sorting Middleware Proceedings:\n\n  The middlewares can be sorted / priority assigned when it is falls under group of middlewares.\n  That can be implemented inside app/Http/Kernel.php file with property name called $middlewarePriority.\n\n  Middleware can accept parameters when implementing.\n\n  ```php\n  Route::put('/post/{id}', function ($id) {\n      //\n  })-\u003emiddleware('role:editor');\n  ```\n\n## Terminable Middleware:\n\n  After response if need to do something with middleware then terminate method will used.\n\n---\n\n# **CSRF Token:**\n\n  CSRF token needed if any form has following method POST, PUT, PATCH and DELETE request methods.\n\n## Creating CSRF Protection:\n\n  Blade directive to generate hidden csrf field using @csrf representation. or equivalent with\n  ```html\n  \u003cinput type=\"hidden\" name=\"_token\" value=\"{{ csrf_token() }}\" /\u003e\n  ```\n\n## Get CSRF Token as following ways:\n\n  ```php\n  $token = $request-\u003esession()-\u003etoken();\n  $token = csrf_token();\n  ```\n\n## Excluding CSRF Protection:\n\n  Adding their URLs to the $except property of the VerifyCsrfToken middleware implementation inside App\\Providers\\RouteServiceProvider class.\n\n  ```php\n  protected $except = [\n      'stripe/*',\n      'http://example.com/foo/bar',\n      'http://example.com/foo/*',\n  ];\n  ```\n\n## X-CSRF-TOKEN:\n\n  The App\\Http\\Middleware\\VerifyCsrfToken middleware will also check for X-CSRF-TOKEN in requests.\n  So, this can be implemented as follows.\n\n  ```html\n  \u003cmeta name=\"csrf-token\" content=\"{{ csrf_token() }}\"\u003e\n  ```\n  ```js\n  $.ajaxSetup({\n      headers: {\n          'X-CSRF-TOKEN': $('meta[name=\"csrf-token\"]').attr('content')\n      }\n  });\n  ```\n\n  Laravel stores the current CSRF token in the form of an encrypted XSRF-TOKEN as cookie.\n\n---\n\n# **Controllers:**\n\n  Controllers are logical block of code that can be control the flow of application request.\n  Controllers can have mulitple methods and some controller may have single method. This controllers are used in the Routes file.\n\n## Creating Controllers:\n\n  `php artisan make:controller ProvisionServer`\n\n## Creating Single Action Controllers:\n\n  `php artisan make:controller ProvisionServer --invokable`\n\n## Creating Resource Controllers:\n\n  This will create default methods for Create, Read, Edit, Update and Delete actions.\n\n  `php artisan make:controller CrudController --resource`\n\n## Creating Controller with resource model:\n\n  This will bind specific model class to the controller with CRUD resources.\n\n  `php artisan make:controller PhotoController --model=Photo --resource`\n\n## Creating Controller with Form Requests:\n\n  This will generate Form Request classes for that controller with CRUD resources.\n\n  `php artisan make:controller PhotoController --model=Photo --resource --requests`\n\n## Single Action Controllers:\n\n  Define and implement __invoke method inside controller class. This will not require to specify method name in Route files.\n\n  `Route::post('/server', ProvisionServer::class);`\n\n## Controller Middleware:\n\n  Middlewares can be implemented inside constructor method or In the Route itself.\n\n## Registering Many Resource Controllers:\n\n  This will redirect to specific method by default for crud operation.\n\n  ```php\n  Route::resources([\n    'photos' =\u003e PhotoController::class,\n    'posts' =\u003e PostController::class,\n  ]);\n  ```\n\n## Missing Model Controller:\n\n  To avoid 404 page not found error and redirect to specific action can be done by adding missing method in Route resources.\n\n  ```php\n  Route::resource('photos', PhotoController::class)-\u003emissing(function (Request $request) {\n      return Redirect::route('photos.index');\n  });\n  ```\n\n## Partial Resource Routes:\n\n  This will redirect to specific method of action that are mentioned here\n\n  ```php\n  Route::resource('photos', PhotoController::class)-\u003eonly([\n    'index', 'show'\n  ]);\n  ```\n\n  This will redirect to specific method except following method of action that are mentioned here\n\n  ```php\n  Route::resource('photos', PhotoController::class)-\u003eexcept([\n    'create', 'store', 'update', 'destroy'\n  ]);\n  ```\n\n## API Resource Routes:\n\n  This will consumed by API requests.\n\n  ```php\n  Route::apiResource('photos', PhotoController::class);\n\n  Route::apiResources([\n      'photos' =\u003e PhotoController::class,\n      'posts' =\u003e PostController::class,\n  ]);\n  ```\n\n## Nested Resources:\n\n  The nested route resources for the requests /photos/{photo}/comments/{comment} will be declared as follows.\n\n  ```php\n  Route::resource('photos.comments', PhotoCommentController::class);\n  ```\n\n## Naming Resources Routes:\n\n  Assigning name for specific method of action.\n\n  ```php\n  Route::resource('photos', PhotoController::class)-\u003enames([\n    'create' =\u003e 'photos.build'\n  ]);\n  ```\n\n## Naming Parameters in Resource Routes:\n\n  To take up named parameter for requested URL /users/{admin_user} defined as follows.\n\n  ```php\n  Route::resource('users', AdminUserController::class)-\u003eparameters([\n    'users' =\u003e 'admin_user'\n  ]);\n  ```\n\n---\n\n# **Requests:**\n\n## Retrieving requested path:\n\n  ```php\n  $uri = $request-\u003epath();\n  ```\n\n## Inspecting / Checking Request Path:\n\n  To check the requested path is starting with admin/ or not.\n\n  ```php\n  if ($request-\u003eis('admin/*')) {\n    //\n  }\n  ```\n\n## Checking Named Request Routes:\n\n  To check the route name is starting with admin or not.\n\n  ```php\n  if ($request-\u003erouteIs('admin.*')) {\n      //\n  }\n  ```\n\n## Retrieving Requested URL:\n  Get requested URL without query string.\n\n  ```php\n  $url = $request-\u003eurl();  \n  ```\n\n  Get requested URL with query string.\n\n  ```php\n  $urlWithQueryString = $request-\u003efullUrl();\n  ```\n\n## Merge query string with requested URL:\n\n  ```php\n  $request-\u003efullUrlWithQuery(['type' =\u003e 'article']);\n  ```\n## Retrieve Requested Host:\n\n  ```php\n  $request-\u003ehost();\n  $request-\u003ehttpHost();\n  $request-\u003eschemeAndHttpHost();\n  ```\n## Retrieve Requested Method:\n\n  Get current requested method.\n  ```php\n  $method = $request-\u003emethod();\n  ```\n\n  Check current request method.\n  ```php\n  if ($request-\u003eisMethod('post')) {\n    //\n  }\n  ```\n\n## Retrieve Requested Headers:\n\n  Get Header value in the request.\n\n  ```php\n  $value = $request-\u003eheader('X-Header-Name');\n  ```\n\n  Get Header value if it not present retrieve default value.\n\n  ```php\n  $value = $request-\u003eheader('X-Header-Name', 'default');\n  ```\n\n  Check the request has specific header.\n\n  ```php\n  if ($request-\u003ehasHeader('X-Header-Name')) {\n    //\n  }\n  ```\n\n  Get authorization header if present.\n\n  ```php\n  $token = $request-\u003ebearerToken();\n  ```\n\n## Get Requested IP Address:\n\n  ```php\n  $ipAddress = $request-\u003eip();\n  ```\n\n## Requested Content Type:\n\n  Get acceptable content type for the request.\n\n  ```php\n  $contentTypes = $request-\u003egetAcceptableContentTypes();\n  ```\n\n  Check acceptable content type for the request which returns either `true` or `false`.\n\n  ```php\n  if ($request-\u003eaccepts(['text/html', 'application/json'])) {\n      // ...\n  }\n  ```\n\n  Checks preferable content type for the request which returns `null` if not present.\n\n  ```php\n  $preferred = $request-\u003eprefers(['text/html', 'application/json']);\n  ```\n\n  Checks expected content type for the request which returns either `true` or `false`.\n  This will suitable for most requested type in web applications.\n  \n  ```php\n  if ($request-\u003eexpectsJson()) {\n    // ...\n  }\n  ```\n\n## PSR-7 Request:\n\n  Laravel supports PSR-7 request type for more see [Laravel-9-documentation](https://laravel.com/docs/9.x/requests#psr7-requests)\n\n## Retrieving All Input Data:\n\n  Get input data as array.\n\n  ```php\n  $input = $request-\u003eall();\n  ```\n\n  Get input data as collection.\n  \n  ```php\n  $input = $request-\u003ecollect();\n  ```\n\n  Get subset incoming request.\n  \n  ```php\n  $request-\u003ecollect('users')-\u003eeach(function ($user) {\n    // ...\n  });\n  ```\n\n## Retrieving Input Values:\n\n  Get specific input values from the request.\n\n  ```php\n  $name = $request-\u003einput('name');\n  ```\n\n  If input value not present get default value.\n\n  ```php\n  $name = $request-\u003einput('name', 'Sally');\n  ```\n\n  Get first index of array input value.\n\n  ```php\n  $name = $request-\u003einput('products.0.name');\n  ```\n\n  Get all array input value.\n\n  ```php\n  $names = $request-\u003einput('products.*.name');\n  ```\n\n  Get all input values as associative array.\n\n  ```php\n  $input = $request-\u003einput();\n  ```\n\n## Retrieving Input From Query:\n\n  Get specific query input value.\n\n  ```php\n  $name = $request-\u003equery('name');\n  ```\n\n  Get specific query value when it not present return default value.\n\n  ```php\n  $name = $request-\u003equery('name', 'Helen');\n  ```\n\n  Get all query string input value.\n\n  ```php\n  $query = $request-\u003equery();\n  ```\n\n## Retrieving JSON Input:\n\n  Get specific input value when JSON request is made.\n\n  ```php\n  $name = $request-\u003einput('user.name');\n  ```\n\n## Retrieving String Input:\n\n  Get specific input value when it is a stringable value.\n\n  ```php\n  $name = $request-\u003estring('name')-\u003etrim();\n  ```\n\n## Retrieving Boolean Input:\n\n  Get specific input value when it is a boolean value.\n\n  ```php\n  $archived = $request-\u003eboolean('archived');\n  ```\n\n## Retrieving Data Input:\n\n  Get specific input value when it is a date value.\n\n  ```php\n  $birthday = $request-\u003edate('birthday');\n  ```\n\n  Get specific date input with timezone and additional formattings.\n\n  ```php\n  $elapsed = $request-\u003edate('elapsed', '!H:i', 'Asia/Kolkata');\n  ```\n\n## Retrieving Input Via Dynamic Property:\n\n  Get specific input value via dynamic property which points form input field name.\n\n  ```php\n  $name = $request-\u003ename;\n  ```\n\n## Retrieving Input Portion:\n\n  Get specific portion of input as array or dynamic list of arguments.\n\n  ```php\n  $input = $request-\u003eonly(['username', 'password']);\n \n  $input = $request-\u003eonly('username', 'password');\n  ```\n\n  Get all portion of input as array or dynamic list of arguments except specific list of input.\n\n  ```php\n  $input = $request-\u003eexcept(['credit_card']);\n \n  $input = $request-\u003eexcept('credit_card');\n  ```\n\n## Check Input Exists:\n\n  Check whether input exists or not.\n\n  ```php\n  if ($request-\u003ehas('name')) {\n    //\n  }\n  ```\n\n  Check specific group of input present or not.\n\n  ```php\n  if ($request-\u003ehas(['name', 'email'])) {\n    //\n  }\n  ```\n\n  Check any one of specific input group present or not which returns `true` or `false`.\n\n  ```php\n  if ($request-\u003ehasAny(['name', 'email'])) {\n      //\n  }\n  ```\n\n  Checks the specific input value not empty or not which returns `true` or `not`.\n\n  ```php\n  if ($request-\u003efilled('name')) {\n    //\n  }\n  ```\n\n  Checks if the input key is missing in request which returns `true` or `false`.\n\n  ```php\n  if ($request-\u003emissing('name')) {\n      //\n  }\n  ```\n\n  Execute closure when specific input value present.\n\n  ```php\n  $request-\u003ewhenHas('name', function ($input) {\n    //\n  });\n  ```\n\n  Execute closure when specific input value present and not present conditions.\n\n  ```php\n  $request-\u003ewhenHas('name', function ($input) {\n    // The \"name\" value is present...\n  }, function () {\n      // The \"name\" value is not present...\n  });\n  ```\n\n  Executes closure when input value is not empty.\n\n  ```php\n  $request-\u003ewhenFilled('name', function ($input) {\n    //\n  });\n  ```\n\n  Execute closure when input value is not empty and empty conditions.\n  \n  ```php\n  $request-\u003ewhenFilled('name', function ($input) {\n    // The \"name\" value is filled...\n  }, function () {\n    // The \"name\" value is not filled...\n  });\n  ```\n\n## Merging Addtional Input:\n\n  Merging additional input values to excisting request.\n\n  ```php\n  $request-\u003emerge(['votes' =\u003e 0]);\n  ```\n\n  Merging additional input values if the key is missing.\n\n  ```php\n  $request-\u003emergeIfMissing(['votes' =\u003e 0]);\n  ```\n\n## Old Input:\n\n  It is useful when handling validation with existing forms to retrieving old form data.\n\n  For more see [Laravel-9-documentation](https://laravel.com/docs/9.x/requests#old-input)\n\n## Flash Input Session:\n\n  The flash method useful to store all input to the flash session until next resquest.\n\n  ```php\n  $request-\u003eflashOnly(['username', 'email']);\n \n  $request-\u003eflashExcept('password');\n  ```\n\n## Flash Input Redirection:\n\n  Redirecting to previous page with old input by chaining the redirection with flash input.\n\n  ```php\n  return redirect('form')-\u003ewithInput();\n  \n  return redirect()-\u003eroute('user.create')-\u003ewithInput();\n  \n  return redirect('form')-\u003ewithInput(\n      $request-\u003eexcept('password')\n  );\n  ```\n\n## Retrieving Old Input:\n\n  Retrieving old input from flash.\n\n  ```php\n  $username = $request-\u003eold('username');\n  ```\n\n  ```html\n  \u003cinput type=\"text\" name=\"username\" value=\"{{ old('username') }}\"\u003e\n  ```\n\n## Retrieving Cookie:\n\n  Retrieving cookie value from request.\n\n  ```php\n  $value = $request-\u003ecookie('name');\n  ```\n\n## Input Trimming \u0026 Normalization:\n\n  Laravel supports Input Trimming and Normalization for more see [Laravel-9-documentation](https://laravel.com/docs/9.x/requests#input-trimming-and-normalization)\n\n## Retrieving Uploaded File:\n\n  Get uploaded file from request.\n\n  ```php\n  $file = $request-\u003efile('photo');\n \n  $file = $request-\u003ephoto;\n  ```\n\n  Check file has uploaded by `hasFile`.\n\n  ```php\n  if ($request-\u003ehasFile('photo')) {\n      //\n  }\n  ```\n\n## Validating File Upload:\n\n  Validate file upload has completed without any problem and it checks any uploaded error during request.\n\n  ```php\n  if ($request-\u003efile('photo')-\u003eisValid()) {\n      //\n  }\n  ```\n\n## File Upload Details:\n\n  Get uploaded file path and extension.\n\n  ```php\n  $path = $request-\u003ephoto-\u003epath();\n \n  $extension = $request-\u003ephoto-\u003eextension();\n  ```\n\n## Store Uploaded File:\n\n  Storing uploaded file.\n\n  ```php\n  $path = $request-\u003ephoto-\u003estore('images');\n \n  $path = $request-\u003ephoto-\u003estore('images', 's3');\n  ```\n\n  Storing uploaded file in a specific disk name.\n\n  ```php\n  $path = $request-\u003ephoto-\u003estoreAs('images', 'filename.jpg');\n \n  $path = $request-\u003ephoto-\u003estoreAs('images', 'filename.jpg', 's3');\n  ```\n\n ## Configuring Trusted Proxies:\n\n  Laravel supports trust proxies for more see [Laravel-9-documentation](https://laravel.com/docs/9.x/requests#configuring-trusted-proxies )\n \n ## Configuring Trusted Host:\n\n  Laravel supports trust host for more see [Laravel-9-documentation](https://laravel.com/docs/9.x/requests#configuring-trusted-hosts)\n  \n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fag-sanjjeev%2Flaravel-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fag-sanjjeev%2Flaravel-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fag-sanjjeev%2Flaravel-notes/lists"}