Generating Basic URLs
The url
helper may be used to generate arbitrary URLs for your application. The generated URL will automatically use the scheme (HTTP or HTTPS) and host from the current request:
$post = App\Post::find(1);
echo url("/posts/{$post->id}");
// http://example.com/posts/1
Accessing The Current URL
If no path is provided to the url
helper, a Illuminate\Routing\UrlGenerator
instance is returned, allowing you to access information about the current URL:
// Get the current URL without the query string...
echo url()->current();
// Get the current URL including the query string...
echo url()->full();
// Get the full URL for the previous request...
echo url()->previous();
URL
facade:
use Illuminate\Support\Facades\URL;
echo URL::current();
Route::get('form', 'demoController@form');
php artisan make:controller demoController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class demoController extends Controller
{
public function form(){
return view('form');
}
}
<!DOCTYPE html>
<html>
<head>
<title>Retrieving Input In laravel</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="text-center">
<h1>Retrieving Input In laravel</h1>
</div>
<div class="form-group col-sm-2"></div>
<div class="form-group col-sm-8">
<div class="well">
<form method="post" action="">
@csrf
<div class="form-group col-sm-12">
<label>UserName</label>
<input class="form-control" type="text" name="username" value="">
</div>
<div class="form-group col-sm-12">
<label>Password</label>
<input class="form-control" type="text" name="password" value="">
</div>
<div class="form-group text-center">
<input class="btn btn-primary" type="submit" >
</div>
</form>
<div class="form-group col-sm-2"></div>
</div>
</div>
<br>
</div>
</body>
</html>
5.Create Url to store requested data so that open demo.blade.php and add below lines in form
demo.blade.php
<form method="post" action="{{url('filestore')}}">
6.Now open routes\web.php file and implement below code in it.so that when form.blade.php files calls filestore url it will goes to route and it will reach demoController
Route::post('formstore', 'demoController@formstore');
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class demoController extends Controller
{
public function form(){
return view('form');
}
public function formstore(Request $request){
return '<h1>'.$request->path().'</h1>';
}
}